Get Unix Epoch Time in Swift
You can simply use NSDate’s timeIntervalSince1970 function. let timeInterval = NSDate().timeIntervalSince1970
You can simply use NSDate’s timeIntervalSince1970 function. let timeInterval = NSDate().timeIntervalSince1970
Update for 0.19 It is not possible to get the current time using the standard library.. You need to use elm/time. As with 0.18, all you need is a command and Msg to handle the result type Msg = OnTime Time.Posix getTime : Cmd Msg getTime = Task.perform OnTime Time.now Update for 0.18 This has … Read more
Keep in mind that the playground has the time set to 2009-11-10 23:00:00 +0000 UTC, so it is working. The proper way is to use time.LoadLocation though, here’s an example: var countryTz = map[string]string{ “Hungary”: “Europe/Budapest”, “Egypt”: “Africa/Cairo”, } func timeIn(name string) time.Time { loc, err := time.LoadLocation(countryTz[name]) if err != nil { panic(err) } … Read more
I use LuaSocket to get more precision. require “socket” print(“Milliseconds: ” .. socket.gettime()*1000) This adds a dependency of course, but works fine for personal use (in benchmarking scripts for example).
If you are on OSX running boot2docker, see this issue: https://github.com/boot2docker/boot2docker/issues/290 Time synch becomes an issue because the boot2docker host has its time drift while your OS is asleep. Time synch with your docker container cannot be resolved by running your container with -v /etc/localtime:/etc/localtime:ro Instead, for now, you have to periodically run this on … Read more
You can do a dns lookup with gethostbyaddr, create a connection with fsockopen, write the HTTP request, wait for the response etc. You can calculate the time after each step. We at www.downnotifier.com use similar ways.