Jonathan Safa
Jonathan Safa

Reputation: 181

Interpret TimeStamp

I am trying to interpret a series of numbers that are representing time so that I can change them in the near future to different numbers. How long is 135671800? And what does each mean? Is it DD:HH:MM:SS?

{"next_timestamp":1356751800,"next_duration":9000,"next_title":"Saturday Night","next_description":"Hearing and Healing"}

The original javascript that is interpreting the result is:

else if (typeof data.next_timestamp !== "undefined") {
        seconds_till = data.next_timestamp - (new Date().getTime() / 1000);
        days = Math.floor((seconds_till % 31536000) / 86400);
        hours = Math.floor((seconds_till % 86400) / 3600);
        minutes = Math.floor((seconds_till % 3600) / 60);
        seconds = Math.floor(seconds_till % 60);
        return intervalId = setInterval(function() {
          if (--seconds < 0) {
            seconds = 59;
            if (--minutes < 0) {
              minutes = 59;
              if (--hours < 0) {
                hours = 23;
                  if (--days < 0) {
                days = 365;
                }
              }
            }
          }

Thanks!

Upvotes: 0

Views: 539

Answers (2)

user1931103
user1931103

Reputation:

If you are working with a standard timestamp you can just use the Javascript Date object.

https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date

var date = new Date(/* timestamp * 1000 here */);
var day = date.getDay();
var month = date.getMonth();
var year = date.getFullYear();

Not sure what your interval is for but if you want to count this back down to 0...

// Assume that date still exists.
time = date.getTime() / 1000;
time--;
date = new Date(time * 1000);
day = date.getDay();
month = date.getMonth();
year = date.getFullYear();

Upvotes: 1

Giorgos Papadakis
Giorgos Papadakis

Reputation: 39

It is seconds from "epoch" (seconds that have elapsed since midnight Coordinated Universal Time (UTC), 1 January 1970). Actually Sat, 29 Dec 2012 03:30:00 GMT

See live counter here http://www.epochconverter.com/

More about UNIX Time http://en.wikipedia.org/wiki/Unix_time

Upvotes: 0

Related Questions