Use golang packets in time

First, the code

main Package; 
 
Import (
     " Time " 
    " FMT " 
) 
 
FUNC main () {
     // time.time represents a nanosecond precision time 
    var T time.time;
     // returns the current time 
    T = Time.now (); 
    FMT .Printf ( " % v \ the n- " , t);
     // zone where the anti-back 
    fmt.Printf ( " % v \ the n- " , t.Location ());
     // zone and return UTC time UTC 
    fmt.Printf ( " V% V% \ n- " , t.UTC (), t.UTC () the Location ());.
     // supra, the in time () returns the specified time zone 
    fmt.Printf (" % V% v \ the n- " , t.In (Time.utc), t.In (Time.utc) .location ());
     // returns the local time zone 
    fmt.Printf ( " % v% v \ the n- " ., t.Local (), t.Local () the Location ());
 
     // The local time stamp returns
     // parameters are the number of seconds and the number of nanoseconds 
    T2: = time.Unix (1487780010 , 0); 
    fmt.Println (T2);
 
     // returns the specified time time.Time
     // are designated year, month, day, hour, minutes, seconds, nanoseconds, the time zone 
    T3: = time.Date (2017, time.Month (. 5 ), 26 is, 15, 30, 20 is , 0, t.Location ()); 
    fmt.Println (T3);
 
     // formatted output time 
    T4: = Time.now (); 
    fmt.Println (t4.Format (" 2006-01-02 15:04:05 " ));
 
     // get time information 
    T5: = Time.now ();
     // return date 
    fmt.Println (t5.Date ());
     // returns in 
    fmt. println (t5.Year ());
     // returns the month 
    fmt.Println (t5.Month ());
     // return date 
    fmt.Println (t5.Day ());
     // returns the week 
    fmt.Println (t5.Weekday ());
     // returns the year and week number in the ISO 9601 standard 
    fmt.Println (t5.ISOWeek ());
     // every second return 
    fmt.Println (t5.Clock ());
     // return hours 
    fmt.Println (t5.Hour ());
     // returns min 
    fmt.Println (t5.Minute ());
    // Returns second 
    fmt.Println (t5.Second ());
     // Returns nanoseconds 
    fmt.Println (t5.Nanosecond ());
     // returns the year corresponding to the day 
    fmt.Println (t5.YearDay ()) ;
     // return zone 
    fmt.Println (t5.Location ());
     // returns the canonical name time zones, the time zone to UTC time offset (s) 
    fmt.Println (t5.Zone ());
     // returns stamp 
    fmt.Println (t5.Unix ());
     // returns nanoseconds timestamp 
    fmt.Println (t5.UnixNano ());
 
     // compared to the calculated time 
    T6: = Time.now ();
     // if zero time 
    fmt.Println (t6.IsZero ());
     // T6 time after time t5, returns true 
    fmt.Println (t6.After (t5));
     //time t6 before time t5, returns true 
    fmt.Println (t5.Before (t6));
     // if the same time 
    fmt.Println (t6.Equal (t6));
     // Returns nanoseconds plus the time t6 
    fmt. println (t6.Add ( 10000 ));
     // returns the difference of two times the number of nanoseconds 
    fmt.Println (t6.Sub (T5));
     // returns t6 plus 1 year, 1 month, 1 day 
    fmt .Println (t6.AddDate ( . 1,. 1,. 1 ));
 
     // serialization time 
    T7: = Time.now ();
     // a sequence of binary 
    bin, _: = t7.MarshalBinary ();
     // deserialization of binary 
    t7.UnmarshalBinary (bin) 
    fmt.Println (T7);
     // serialized JSON 
    JSON, _:= T7.MarshalJSON (); 
    fmt.Println (String (JSON));
     // deserialize JSON 
    t7.UnmarshalJSON (JSON); 
    fmt.Println (T7);
     // sequence of text 
    TXT, _: = t7.MarshalText (); 
    fmt.Println (String (TXT));
     // deserialization text 
    t7.UnmarshalText (TXT); 
    fmt.Println (T7);
     // GOB coding 
    GOB, _: = t7.GobEncode (); 
    T7. GobDecode (GOB); 
    fmt.Println (T7);
 
     // time time.Duration 
    DUR: = time.Duration (6,666,666,600,000 );
     // returns a string representation 
    fmt.Println (dur.String ());
     //Returns h represents 
    fmt.Println (dur.Hours ());
     // Returns min represents 
    fmt.Println (dur.Minutes ());
     // Returns seconds 
    fmt.Println (dur.Seconds ());
     // Returns sodium seconds 
    fmt.Println (dur.Nanoseconds ());
 
     // time zone time.Location
     // return zone name 
    fmt.Println (time.Local.String ());
 
     // the offset region when the amount of time and place names returned by 
    fmt. println (time.FixedZone ( " of Shanghai " , 800 ));
 
     // by names given time zone, the return region 
    LOC, _: = time.LoadLocation ( " Asia / of Shanghai " ); 
    fmt.Println (LOC);
 
     // blocked the current process 3 seconds
    the time.sleep (time.Second * 3 );
 
     // timer time.Timer
     // After creating a one second shot timer 
    timer1: = time.NewTimer (time.Second * 1 );
     <- timer1.C; 
    fmt. println ( " Timer1 End " );
 
     // run 1 second after the function 
    time.AfterFunc (time.Second *. 1 , FUNC () { 
        fmt.Println ( " the wait SECOND. 1 " ); 
    }); 
    time.sleep (time.Second * 3 );
 
     // RBI time.Ticker
     // Create a RBI, is repeatedly performed within a fixed one second 
    TICKER: =time.NewTicker (time.Second); 
    NUM: =. 1 ;
     for {
         IF NUM> 5 {
             // more than 5 times closed RBI 
            ticker.Stop (); 
            BREAK ; 
        }
         // otherwise acquired from RBI chan 
        SELECT { 
        Case <- ticker.C: 
            NUM ++ ; 
            fmt.Println ( " . 1 SECOND ... " ); 
        } 
    } 
}

 

Guess you like

Origin www.cnblogs.com/angelyan/p/11104610.html