PHP中格式化时间很方便,只需要一个函数就搞定:

date("Y-m-d H:i:s")

而在Golang中,用的是"2006-01-02 15:04:05"这样的layout string:

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

2006表示year

01表示month

02表示day

15表示hour

04表示minute

05表示seconds

只能用以上这几个数字来格式化时间,假如把这里的2006改写成2008就不能正确格式化时间。

这个有点奇怪,不过golang不管在文法结构上,还是执行效率上,都有其长处,值得你把golang带入你的项目中。

Golang时间格式化的更多相关文章

  1. golang 时间戳 时间格式化 获取当前时间 timestamp 计算时间差

    获取当前时间 func Now func Now() Time 1 Now returns the current local time. func (Time) UTC func (t Time) ...

  2. strftime 日期时间格式化

    strftime() 函数根据区域设置格式化本地时间/日期,函数的功能将时间格式化,或者说格式化一个时间字符串. size_t strftime(char *strDest,size_t maxsiz ...

  3. javascript 时间格式化

    添加扩展 //时间格式化扩展Date.prototype.format = function(format){ var o = { "M+" : this.getMonth()+1 ...

  4. js时间格式化

    const formatDate = timestamp => { const date = new Date(timestamp); const m = date.getMonth() + 1 ...

  5. js对特殊字符转义、时间格式化、获取URL参数

    /*特殊字符转义*/ function replace_html(str) { var str = str.toString().replace(/&/g, "&" ...

  6. 特殊字符转义&时间格式化&获取URL参数

    /*特殊字符转义*/ function htmlspecialchars (str) { var str = str.toString().replace(/&/g, "&& ...

  7. 【AspNetCore】【WebApi】扩展Webapi中的RouteConstraint中,让DateTime类型,支持时间格式化(DateTimeFormat)

    扩展Webapi中的RouteConstraint中,让DateTime类型,支持时间格式化(DateTimeFormat) 一.背景 大家在使用WebApi时,会用到DateTime为参数,类似于这 ...

  8. EasyUI Datagrid Datetime(EasyUI DataGrid 时间格式化)

    EasyUI DataGrid 时间格式化 方法一: var Common = { //EasyUI用DataGrid用日期格式化 TimeFormatter: function (value, re ...

  9. js Date 时间格式化的扩展

    js Date 时间格式化的扩展: Date.prototype.format = function (fmt) { var o = { , //月 "d+": this.getD ...

随机推荐

  1. bzoj:1584: [Usaco2009 Mar]Cleaning Up 打扫卫生

    Description 有N头奶牛,每头那牛都有一个标号Pi,1 <= Pi <= M <= N <= 40000.现在Farmer John要把这些奶牛分成若干段,定义每段的 ...

  2. Codeforces Round #426 (Div. 2)【A.枚举,B.思维,C,二分+数学】

    A. The Useless Toy time limit per test:1 second memory limit per test:256 megabytes input:standard i ...

  3. Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3)(A.B.C,3道暴力题,C可二分求解)

    A. Is it rated? time limit per test:2 seconds memory limit per test:256 megabytes input:standard inp ...

  4. HDU 2289 Cup【高精度,二分】

    Cup Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  5. 剪邮票dfs+bfs+组合+结构体

    #include<iostream>#include<queue>using namespace std;struct Point{ int x; int y; };queue ...

  6. UE4 保存为bitmap

    TArray<FColor> colorData;    colorData.Init(FColor(0, 0, 255, 255), 1920 * 1080);    for (int ...

  7. javascript数据类型及转换

    此篇数据类型和转换只限于ECMA规范,规范用了比较大的篇幅讲数据类型和类型转换,理解了这个最基本的概念对表达式.语句.执行环境.对象及继承都有非常大的帮助,遂整理如下: 数据类型和值 类型转换 表达式 ...

  8. Spark算子--distinct

    distinct--Transformation类算子 代码示例    

  9. Spark算子--mapPartitions和mapPartitionsWithIndex

    mapPartitions--Transformation类算子 代码示例 result   mapPartitionsWithIndex--Transformation类算子 代码示例 result ...

  10. 如何使用cmd打开磁盘目录和文件

    在windows操作系统中拥有命令行工具(cmd).cmd具有强大的功能,这里我就和大家介绍一下怎么使用cmd命令打开文件. 工具/原料 cmd命令行 打开cmd 1 在windows操作系统中按住w ...