UNIX timestamp 2 hours out of sync

Started by duanebutler, January 19, 2016, 10:19:31 AM

Previous topic - Next topic

duanebutler

Hi There

I have been struggling with the UNIX timestamp conversion a while now.  I finally got it working but now for whatever reason the time stamp DCI value netxms pulls is 2 hours behind exactly.

I did a online converter of the timestamp as well and i get the same results.

More info:
I poll dci value using File.Time.Modify parameter.  I then use a script to convert from UNIX time. However, DCI value being polled is 2 hours behind the actual value.

Please assist.

Regards

tomaskir

How are you collecting the timestamp and how are you transforming it?
It sounds like your transformation happends in UTC, whereas your timezone is +2.

You can see how NXSL time-related functions work in this example script:

// current time in Unix time
timeVar = time();

// lets convert to time object in UTC timezone
timeGM = gmtime(timeVar);

// lets convert to time object in our local timezone
timeLocal = localtime(timeVar);

// lets print all of them
// remember this is in UTC timezone
println(timeGM->year . "-" . 1 + timeGM->mon . "-" . timeGM->mday . " " . timeGM->hour . ":" . timeGM->min);
// this one will be in our local time, because we are using localtime() function
println(timeLocal->year . "-" . 1 + timeLocal->mon . "-" . timeLocal->mday . " " . timeLocal->hour . ":" . timeLocal->min);
// this one should be the same, since strftime() function works in localtime
println(strftime("%Y-%m-%d %H:%M - timezone %Z - offset from UTC - %z", timeVar));

duanebutler

Thanx for the speedy reply.

I actually found what my issue was. i was using the gmtime function and just changed to localtime and it works 100% now :)

I used basics here but nonetheless it works  :D

day = localtime($1)->mday;

mon = localtime($1)->mon+1;

year = localtime($1)->year;

hour = localtime($1)->hour;

min = localtime($1)->min;

return day."-".mon."-".year."/".hour.":".min;


I could have just added a variable t = ($1) to make it even easier.

Thanx for the advice and putting me in the right direction.