# Amount of seconds, since like... ever?

This forum is currently in read-only mode.
0 favourites
• 10 posts
• I'm stumped. DOes anyone have any ideas on how to get the amount of seconds since, let's say, Jan 1 1970.

The reason I needs this is my game logs the last time you played and updates what happened during the time you started again. So I need to know how that's been.

Thanks again for all the help.

• Could probably do that using the "date" object. I don't think there's an explicit "seconds since x", but if you hold the year, month, day etc. in a file on closing, you could probably compare those values against the current on opening.

• Yeah, the Date objects the way to go.

Compare the start date to the current date and use:

31536000 seconds per year

86400 seconds per day

3600 seconds per hour

etc

etc

Krush.

• That's what I was thinking, but I can't figure out how to implement it. Since the days only show what day of the month it is (Not what day of the year), I'd have to include months, but then since all months are not equal, (not even factoring leap years), it becomes quite a mess. I was wondering if anyone had any smart ideas on how to implement this.

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• I don't see an accurate way of doing it without factoring in the different months and leap years.

Shouldn't be too diffifcult.

Let's say TotalSeconds is the variable you're using:

(first the amount of years): TotalSeconds=TotalSeconds + (years*31536000)

(now the months):If month is later than January : TotalSeconds=TotalSeconds + (31*86400)

If month is later than February and NOT leap year : TotalSeconds=TotalSeconds + (28*86400)

If month is later than February and a leap year : TotalSeconds=TotalSeconds + (29*86400)

etc

and then you're just left with the days and hours.

Of course, because you're using constant numbers for the months you wouldn't need to use maths like 31*86400 as you could use 2678400, which would mean you wouldn't need to use the brackets then either.

14 or so lines of code and you'd have your seconds stored in your variable.

Done!

Krush.

• Thanks for the help. I'm trying to make it work, but it's going to be messy.

P.S. I just had a thought is there an easy way to do this in python? Or if some lovely coder whould like to make a plugin for this. It'd be great!

• Prepare to be floored, for I have made my most amazing plugin ever:

Unix Time(best used before 2038)

I looked into Python solutions for this, but the number I kept getting rarely updated. Even if you closed out the program and reran it, you'd most likely get the same number you had before since it's updating at most once every two minutes.

• Oh my god! Thank You! this is perfect!!!!

• Awesome, this will be really useful somehow, I'm sure >_<

At least, this is very used with networking so yeah. Put it in the finished addons page!

• Put it in the finished addons page!

Yay.