Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse
Brand Logo

NetXMS Forum

  1. Home
  2. Support
  3. UNIX timestamp 2 hours out of sync

UNIX timestamp 2 hours out of sync

Scheduled Pinned Locked Moved Support
3 Posts 2 Posters 12.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D
    D
    duanebutler
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • T
      T
      tomaskir
      wrote on last edited by
      #2

      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));
      
      1 Reply Last reply
      0
      • D
        D
        duanebutler
        wrote on last edited by
        #3

        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  😄

        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.

        1 Reply Last reply
        0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        Powered by NodeBB Contributors
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups