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

### » Fri Jan 29, 2010 1:01 am

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.
B
33
S
14
G
4
Posts: 251
Reputation: 4,049

### » Fri Jan 29, 2010 3:07 am

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.
B
3
G
3
Posts: 46
Reputation: 967

### » Fri Jan 29, 2010 3:46 pm

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.
B
2
S
2
G
3
Posts: 406
Reputation: 2,062

### » Fri Jan 29, 2010 4:08 pm

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.
B
33
S
14
G
4
Posts: 251
Reputation: 4,049

### » Fri Jan 29, 2010 7:50 pm

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:

[color=#00BF00:a7e0rvmx](first the amount of years):[/color:a7e0rvmx] TotalSeconds=TotalSeconds + (years*31536000)
[color=#00BF00:a7e0rvmx](now the months):[/color:a7e0rvmx]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.
B
2
S
2
G
3
Posts: 406
Reputation: 2,062

### » Sat Jan 30, 2010 1:23 am

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!
B
33
S
14
G
4
Posts: 251
Reputation: 4,049

### » Sat Jan 30, 2010 4:47 am

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.
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

### » Sat Jan 30, 2010 5:06 am

Oh my god! Thank You! this is perfect!!!!
B
33
S
14
G
4
Posts: 251
Reputation: 4,049

### » Sat Jan 30, 2010 5:40 pm

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!
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

### » Sat Jan 30, 2010 6:29 pm

Yay.
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

Next