Can't get correct hour

I want to get correct current time (h:m:s).
As you can see from my log, only ‘year’, ‘min’ and ‘sec’ are correct.
Should I config anything from my Imp?

Thanks!

Code

server.log("time: " + hour + ": " +min+ ": "+sec); server.log("day:"+date(timestamp).day+" m:"+date(timestamp).month+" y:"+date(timestamp).year);

Log

2013-11-24 21:18:31 UTC-5: [Device] time: 2: 18: 30 2013-11-24 21:18:31 UTC-5: [Device] day:25 m:10 y:2013

It probably is Greenwich time (GMT) , not adapted for your timezone.

maybe this code makes it clear:
`// Register with the server
imp.configure(“Timestamp”, [], []);
local timezone =-5; //GMT-5
//dls <- date(time());
daylightsavings <- false;
daylightsavings_start_date <- [20130331 , 20140330 , 20150329, 20160327, 20170326];
daylightsavings_start_time <- 200;
daylightsavings_stop_date <- [20131027 ,20141026 ,20151025 ,20161030 ,20171029];
daylightsavings_stop_time <- 300;
function DaylightSavings(){
local d = date(time() + (timezone6060)); // get the date in your timezone
local datestring = format("%04d%02d%02d-%02d:%02d:%02d", d.year, d.month+1, d.day, d.hour, d.min, d.sec); //e.g. 20130511-00:57:25

daylightsavings_date <- format("%04d%02d%02d", d.year, d.month+1, d.day).tointeger();
daylightsavings_time <- format("%02d%02d", d.hour, d.min).tointeger();

local ds_start = daylightsavings_start_date[(d.year-2013)];
local ds_stop = daylightsavings_stop_date[(d.year-2013)];

if(daylightsavings_date > ds_start) {
if(daylightsavings_date < ds_stop) {
daylightsavings = true;
}
}
if(daylightsavings_date == ds_start){
daylightsavings = true;
if(daylightsavings_time < daylightsavings_start_time){
daylightsavings = false;
}
}
if(daylightsavings_date == ds_stop){
daylightsavings = true;
if(daylightsavings_time > daylightsavings_stop_time){
daylightsavings = false;
}
}
if (daylightsavings){
local d = date(time() + ((timezone + 1)6060)); // get the date in your timezone
datestring = format("%04d%02d%02d-%02d:%02d:%02d", d.year, d.month+1, d.day, d.hour, d.min, d.sec); //e.g. 20130511-00:57:25

}
server.log(datestring);
server.log(daylightsavings_date);
server.log(daylightsavings_time);
server.log("ds_start is " + ds_start);
server.log("ds_stop  is " + ds_stop);
server.log("timezone is " + timezone);
server.log("daylightsavings is " + daylightsavings);
return datestring;

}
server.log("Timestamp = " + DaylightSavings());

// End of code.
`

I’ve tried to put ‘u’ or ‘l’ into date() function, like this date(time, ‘u’). But time result is still not correct :-/.

@DolfTraanberg, wow big thanks!! Your code works!! Can we put your code somewhere into official example and try to explain more on Time function?

I believe there are a number of people working on writing Squirrel docs

If you want to have the time offset (and some weather info) without a local table (by supplying local address info), you can get it from Google and openweathermap.org like this (Agent & Device code):