doucang8303 2016-09-20 09:46
浏览 69
已采纳

如何将日期从一种格式转换为另一种golang

I am converting a date into unix timestamp and fetching the date using split as follows

tm := time.Unix(1470009600, 0).UTC()
dateString := strings.Split(tm.String(), " ")

The output of dateString is 2016-07-15 i.e. YYYY-MM-DD format. How can I convert this into DD-MMM-YY format? eg: 15-Jul-16?

  • 写回答

1条回答 默认 最新

  • doudiemei2013 2016-09-20 09:50
    关注

    Use Format method with the appropriate format:

    fmt.Println(tm.Format("02-Jan-06")) // Prints "01-Aug-16".
    

    Playground: https://play.golang.org/p/uYDYzPwnbJ.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用三极管设计一个单管共射放大电路
  • ¥20 fluent无法启动
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架