-
Notifications
You must be signed in to change notification settings - Fork 1
/
time.go
45 lines (32 loc) · 874 Bytes
/
time.go
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"strconv"
"time"
)
func obtainSystemTime(format string) (string, error) {
currentTime := time.Now()
switch format {
case "ansic":
return currentTime.Format(time.ANSIC), nil
case "unix_date":
return currentTime.Format(time.UnixDate), nil
case "ruby_date":
return currentTime.Format(time.RubyDate), nil
case "rfc822":
return currentTime.Format(time.RFC822), nil
case "rfc822z":
return currentTime.Format(time.RFC822Z), nil
case "rfc850":
return currentTime.Format(time.RFC850), nil
case "rfc1123":
return currentTime.Format(time.RFC1123), nil
case "rfc1123z":
return currentTime.Format(time.RFC1123Z), nil
case "rfc3339":
return currentTime.Format(time.RFC3339), nil
case "rfc3339nano":
return currentTime.Format(time.RFC3339Nano), nil
default:
return strconv.FormatInt(currentTime.Unix(), 10), nil
}
}