Golang- time and date related functions

Golang- time and date related functions

  Basic introduction

    Description: In programming, the programmer will often use the date-related functions, such as: statistical piece of code execution time spent, and so on.
    1) the time and date related functions, packets need to import time

      

 

 

     2) time.Time type, for indicating time

       

 

 

     3) how to get to the other date information

        

    4) the date and time format
      mode 1: Printf is used or SPrintf

        

 

 

       Second way: using time.Format () method completes:

            

        The above description of the code:
        "2006/01/02 15:04:05" is the respective number string is fixed, must be written.
        "2006/01/02 15:04:05" This combination of each string numbers are free, so you can program according to the needs of the time and date to return

     

    Constant 5) Time

const ( 
      Nanosecond the Duration =. 1 // ns 
      Microsecond = 1000 * Nanosecond // sec 
      Millisecond = 1000 * Microsecond // ms Second = 1000 * Millisecond // sec 
      Minute = 60 * Second // min 
      Hour = 60 * Minute // hours 
    )

      The effects of constants: the program can be used to obtain a given time period of time such as 100 milliseconds want Millisecond Time * 100.
    . 6) used in combination at Sleep time constant

      

 

     7) time Unix and methods UnixNano

      

       

 

       The results obtained:

       

 

   

Classroom time and date of the exercise
  to write a piece of code to perform the statistical function of time test03

    

 

Guess you like

Origin www.cnblogs.com/Essaycode/p/12642415.html