The go language calculates the time difference between two times.

Source: Internet
Author: User
Tags difference between two times
This article mainly introduces the time difference between two go language computing methods, involving Python operation time skills. if you need a friend, refer to the example below to describe the time difference between two go language computing methods. Share it with you for your reference. The specific analysis is as follows:

The go language calculates the time difference between the two time periods. the code is very simple. it returns the time from one day ago, one week ago, or before January 1, January.

Package mainimport ("fmt" "time") func main () {// The Add method is the opposite of the Sub method, obtain the time distance between t0 and t1. d is to use Sub // Add t0 to d to obtain t1. Then, use the Add method k: = time. now () // d, _: = time. parseDuration ("-24 h") fmt. println (k. add (d) // fmt a week ago. println (k. add (d * 7) // fmt before January 1, January. println (k. add (d * 30 ))}

I hope this article will help you with Python programming.

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.