swift - convert json marshall time to nsdate -


when marshall time.now() json object gives result "2009-11-10t23:00:00z" printing time.now gives 2009-11-10 23:00:00 +0000 utc. why different. t , z. how can convert swift nsdate object according this table?

the meaning of values irrelevant, they're part of format (iso8601). there couple approaches this. 1 define custom marshaljson() method time or struct , use format date, other represent string in struct in first place when default implementation executes result you're looking for.

the method you'll need use is; time.format(format string) golang docs show example using it;

package main  import (     "fmt"     "time" )  func main() {     // layout shows example how reference time should represented.     const layout = "jan 2, 2006 @ 3:04pm (mst)"     t := time.date(2009, time.november, 10, 15, 0, 0, 0, time.local)     fmt.println(t.format(layout))     fmt.println(t.utc().format(layout)) } 

the medium date format in link example use string "jan. 2, 2006"


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -