GO gets the year, month, and date of the time

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

A lot of information on the Web provides an example of how time will be converted into strings, but how the time is divided into years, months, and days respectively, for example:
, the date is displayed, and the month is shown below. As a beginner, that the information on the Internet a bit to read, record, but also look treatise.

The first thing to do is to get a variable of type time, and then use now, if you want to get it, but what about the data you read from the database? Described below:

Get system time directly

year:=time.Now().Year()month:=time.Now().Month()//time.Now().Month().String()day:=time.Now().Day()

Referencing time data in a database

month = time.Unix(dynamic.UpdateTime/10000).Month().String()day = time.Unix(dynamic.UpdateTime/10000).Day()year = time.Unix(dynamic.UpdateTime/10000).Year()

where the dynamic. UpdateTime is the time field that is read from the database, and then the month, date, and so on.

Of course, you can also add several fields (without JSON) to the structure to facilitate the display of the front end. It is important to note that year and day are all int types, and month is a string type.

In fact, this is relatively simple, but as a beginner does not know very well, hope to help.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.