doulan1866 2016-01-07 18:23
浏览 46

转到构建标签-在Windows上获取时间戳

I have seen the following command to set build version

go build -ldflags "-X main.minversion `date -u +.%Y%m%d%.H%M%S`" service.go

but I cant get the timestamp part to work on Windows !

I am using go 1.5 with the following arguments...

build -i -ldflags "-X main.SERVER_NAME=MFFP -X main.VERSION=1.0.0 -X main.BUILD_DATE=`date -u +.%Y%m%d%.H%M%S`"

The error is with the date part

Is this error system related? Anyone tried this on Windows?

Thanks!

  • 写回答

1条回答 默认 最新

  • douhuanglou1445 2016-01-07 19:17
    关注

    The command on *nix systems is using backtick command substitution. date is a built-in on POSIX, and anything inside `s is interpreted as a shell command and is replaced by its value.

    cmd.exe doesn't do command substitution inside backticks at all, There's some ways to accomplish the same thing using for /F delims="", aka the most powerful command in Windows shell, but it's pretty hacky. Maybe use powershell instead, which supports the $(command) syntax?

    PS C:\users\adsmith> go build -i -ldflags "-X main.SERVER_NAME=MFFP -X main.VERSION=1.0.0 -X main.BUILD_DATE=$(Get-Date -uformat .%Y%m%d%.H%M%S)"
    

    You might have to play with the format -- I'm not sure what that's supposed to look like on POSIX. This outputs:

    .20160107.111641
    // Jan 7th 2016, 11:16:41
    
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c