Recent Comments
Link
Recent Posts
Today
Total
«   2025/03   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
관리 메뉴

Study Memory Work

[Go Land] Time 본문

Programing/Go

[Go Land] Time

Hera Choi 2023. 2. 23. 15:42
package main

import (
    "fmt"
    "time"
)

func main() {
    p := fmt.Println

    now := time.Now()
    p(now)							// 2012-10-31 15:50:13.793654 +0000 UTC

    then := time.Date(
        2009, 11, 17, 20, 34, 58, 651387237, time.UTC)
    p(then)							// 2009-11-17 20:34:58.651387237 +0000 UTC

    p(then.Year())
    p(then.Month())
    p(then.Day())
    p(then.Hour())
    p(then.Minute())
    p(then.Second())
    p(then.Nanosecond())
    p(then.Location())

    p(then.Weekday())

    p(then.Before(now))		
    p(then.After(now))
    p(then.Equal(now))

    diff := now.Sub(then)
    p(diff)							// 25891h15m15.142266763s

    p(diff.Hours())					// 25891.25420618521
    p(diff.Minutes())				// 1.5534752523711128e+06
    p(diff.Seconds())				// 9.320851514226677e+07
    p(diff.Nanoseconds())			// 93208515142266763

    p(then.Add(diff))				// 2012-10-31 15:50:13.793654 +0000 UTC
    p(then.Add(-diff))				// 2006-12-05 01:19:43.509120474 +0000 UTC
}

'Programing > Go' 카테고리의 다른 글

[Go Lang] File IO : 파일 쓰기  (0) 2023.02.27
[Go Lang] 에러처리  (0) 2023.02.27
[Go Lang] String Formatting  (0) 2023.02.23
[Go Lang] String Function  (0) 2023.02.23
[Go Lang] Go by Example  (0) 2023.02.22