The problem of time formatting in go language

problem description

encountered a time string of such format: 2018-07-15T16:00:00.000Z

what result do you expect? What is the error message actually seen?

1. What is the time format?
2. How to format it, for example, 2018-07-15 16:00:00

Dec.19,2021

this format is an Internet standard timestamp. You can take a look at RFC3339

.

first of all, you need to parse, and parse needs to use time.Parse,. This method has two parameters, the first is the time format to be parsed, and the second is the time to be parsed. Because Internet standard timestamps are commonly used, the format time.RFC3339 is given in the time library.

t, err := time.Parse(time.RFC3339, "2018-07-15T16:00:00.000Z")

after parsing, t is a time.Time structure, and then you can format it any way you want.

< hr >

at the end: if you have seen the documentation of golang's official time library, it gives samples in this format. So if you want to learn a language, you'd better read the official documents honestly

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4c76d-273f3.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4c76d-273f3.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?