Go----time.Now().Format("2006-01-02 15:04:05)

使用time.Now().Format("2006-01-02 15:04:05),对时间进行格式化输出。
那2006-01-02 15:04:05 这个时间可以不可以改其他的呢?

java中关于时间格式化,一般是用

 Date date = new Date();
 String str = "yyyy-MM-dd HH:mm:ss";
 SimpleDateFormat sdf = new SimpleDateFormat(str);
 System.out.println(sdf.format(date));

而在go中,

含义
月份 1,01,Jan,January
2,02,_2
3,03,15,PM,pm,AM,am
4,04
5,05
06,2006
时区 -07,-0700,-07:00,MST
周几 Mon,Monday

比如
03pm :表示用24小时制表示 am/pm表示上下午 ,保留前导0表示

字符表示: 2020 03 01 13:42
goLayout: 2006 01 02 15: 04

字符表示: 2020-03 13时
goLayout: 2006-01 15时

字符表示:20年 3月1日
goLayout: 06年 1月2日

就记住123456,往下写就可以了。比java记yyyy,MM,mm(还有大小写的啥的),要好记一些

补充: 获取当前时间戳

int32(time.Now().Unix())
发布了27 篇原创文章 · 获赞 1 · 访问量 1187

猜你喜欢

转载自blog.csdn.net/qq_40484416/article/details/104591004