Created
June 9, 2016 12:00
-
-
Save bijayrungta/1540b9db7c90ced6d6f7a1ed410a11a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
import "strconv" | |
import "time" | |
const ( | |
JADE_TS = "2006-01-02 15:04:05.000Z07:00" | |
JRFC3339 = "2006-01-02T15:04:05Z07:00" | |
) | |
func main() { | |
inputTimestamp := "2016-05-10 13:28:31.035" | |
inputTimestamp2 := "2016-05-10 13:28:31.035+00:00" | |
t5, _ := time.Parse("2006-01-02 15:04:05.000", inputTimestamp) | |
p := fmt.Println | |
p("inputTimestampRaw: " + t5.String()) | |
p("inputTimestamp: " + t5.Format(JADE_TS)) | |
p("JADETS: " + time.Now().Format(JADE_TS)) | |
p("RFC3339: " + time.Now().Format(time.RFC3339)) | |
return | |
// Here's a basic example of formatting a time | |
// according to RFC3339, using the corresponding layout | |
// constant. | |
t := time.Now() | |
p("t.Format(time.RFC3339):", t.Format(time.RFC3339)) | |
// p("t.Format('2006-01-02T15:04:05.999-07:00')", t.Format("2006-01-02T15:04:05.999-07:00")) | |
// p("t.Format('2006-01-02T15:04:05.999999-07:00')", t.Format("2006-01-02T15:04:05.999999-07:00")) | |
// p(inputTimestamp) | |
// Time parsing uses the same layout values as `Format`. | |
t1, _ := time.Parse( | |
"2006-01-02 15:04:05.999+05:30", | |
inputTimestamp) | |
p("inputTimestamp1", t1) | |
// Time parsing uses the same layout values as `Format`. | |
t2, _ := time.Parse( | |
time.RFC3339, | |
inputTimestamp2) | |
p("inputTimestamp2", t2) | |
p(time.Parse(time.UnixDate, "Sat Mar 7 11:06:39 PST 2015")) | |
/* | |
// `Format` and `Parse` use example-based layouts. Usually | |
// you'll use a constant from `time` for these layouts, but | |
// you can also supply custom layouts. Layouts must use the | |
// reference time `Mon Jan 2 15:04:05 MST 2006` to show the | |
// pattern with which to format/parse a given time/string. | |
// The example time must be exactly as shown: the year 2006, | |
// 15 for the hour, Monday for the day of the week, etc. | |
p(t.Format("3:04PM")) | |
p(t.Format("Mon Jan _2 15:04:05 2006")) | |
p(t.Format("2006-01-02T15:04:05.999999-07:00")) | |
form := "3 04 PM" | |
t2, e := time.Parse(form, "8 41 PM") | |
p(t2) | |
// For purely numeric representations you can also | |
// use standard string formatting with the extracted | |
// components of the time value. | |
fmt.Printf("%d-%02d-%02dT%02d:%02d:%02d-00:00\n", | |
t.Year(), t.Month(), t.Day(), | |
t.Hour(), t.Minute(), t.Second()) | |
// `Parse` will return an error on malformed input | |
// explaining the parsing problem. | |
ansic := "Mon Jan _2 15:04:05 2006" | |
_, e = time.Parse(ansic, "8:41PM") | |
p(e)*/ | |
return | |
_ = msToTime("1352397861001") | |
} | |
func msToTime(ms string) (time.Time) { | |
msInt, err := strconv.ParseInt(ms, 10, 64) | |
if err != nil { | |
return time.Time{} | |
} | |
t := time.Unix(0, msInt*int64(time.Millisecond)) | |
fmt.Println(t.Format("2006-01-02 15:04:05")) | |
return t | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment