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 多电路系统共用电源的串扰问题
  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料