当前位置:网站首页>go语言time.Format的坑
go语言time.Format的坑
2022-06-09 11:36:00 【.番茄炒蛋】
问题描述
Format以后输出的时间与now是不一样的
package main
import (
"fmt"
"time"
)
func main() {
now := time.Now()
fmt.Println(now)
format := now.Format("2006-01-01 15:04:05")
fmt.Println(format)
}

解决办法
package main
import (
"fmt"
"time"
)
func main() {
now := time.Now()
fmt.Println(now)
format := now.Format("2006-01-02 15:04:05")
fmt.Println(format)
}

使用time.Format格式化时间参数layout必须要传"2006-01-02 15:04:05",为什么呢?没有为什么,这就是最坑的地方,据说这个日期是GO语言的诞生时间,格式化时就必须要传这个时间,传其他的时间都会有问题.
边栏推荐
- [reprint] what is the "brain crack" of distributed systems?
- 清空表格选中项clearSelection
- curator - 节点类型
- LeetCode相机最小问题
- AGCO AI frontier promotion (6.9)
- 科研论文写作
- 盘点现有开源软件许可合规工具
- H3C Certified Wireless senior engineer
- 03 | definition of China Taiwan: what are we talking about when we talk about China Taiwan?
- MySQL optimistic lock, pessimistic lock and multi granularity lock
猜你喜欢

LR11安装报错:此计算机上缺少vc2005_sp1_with_atl_fix_redist,请安装所有缺少的必要组件,然后重新运行此安装。

7. < tag backtracking and subset problem > lt.70 Subset + lt.90 Subset II

leetcode 1332. Remove Palindromic Subsequences(删掉回文子串)

flutter Dio示例

【管理知多少】中文“其他”、英文“OTHER”、日文“その他”.......

中國科學院院刊 | 包雲崗:加速發展關鍵核心技術,必須把握技術發展的自身規律

SIGIR 2022 | CMI:结合对比学习和多兴趣挖掘的微视频推荐

ThreadPoolExecutor 从精通到入门

8.搜索插入位置

7.移除元素
随机推荐
虚拟机出现entering emergency mode,使用xfs_rapair出现Device or resource busy解决
H3C Certified Safety Technology Senior Engineer
UDP reliability practices
3.<tag-回溯和组合及其剪枝>lt.17. 电话号码的字母组合
内核中_init,_exit中的作用
11.<tag-二叉树和BST基础>lt.501. 二叉搜索树中的众数
还有新产品?丰田GR系列或将扩充产品线
go-zero 微服务实战系列(二、服务拆分)
Anonymous inner classes and local variables
PMP project management knowledge system
Relay alphafold! Star pharmaceutical science and technology released a new era of tbind opening molecular protein complex structure prediction
15 Win32 class library name in WMI
Zotero | 文献关联
从2022年的这几篇论文看推荐系统序列建模的趋势
06 | the first step of China Taiwan landing: enterprise strategy decomposition and current situation research (Discovery)
JMeter安装教程
Aiko ai Frontier promotion (6.9)
6.<tag-回溯和切割问题>lt.131.分割回文串
HEVC之HM学习02
dotnet core 也能协调分布式事务啦!