Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Number of seconds to time

Author
Message
Rocco Sette
7
Years of Service
User Offline
Joined: 2nd Aug 2017
Location:
Posted: 30th Sep 2018 11:09 Edited at: 30th Sep 2018 11:11
Good morning,

I'm trying to get the differences between now and a date, and i convert it to seconds.

After that, i'm trying to convert the seconds differences to seconds minutes hours days months and years.

I made this, but if i put the last year, the ouput is not correct.

Someone as an idea ?



GetUnixTime() + 60*60*2 because i want french hour.

Thank's
Rocco Sette
7
Years of Service
User Offline
Joined: 2nd Aug 2017
Location:
Posted: 30th Sep 2018 22:41
I updated to this, number of days is wrong...

If someone know

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 1st Oct 2018 04:57
Don't forget that the number of days in a months varies and to account for leap years. I'll write something up tomorrow if I find the time (way past bedtime for me tonight)
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Rocco Sette
7
Years of Service
User Offline
Joined: 2nd Aug 2017
Location:
Posted: 1st Oct 2018 09:17
Nice, i wait for that

Here my last version :

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 1st Oct 2018 19:50 Edited at: 2nd Oct 2018 13:23
Does this work for you? Since the dates are already being converted to seconds, that function should already account for all the variables I mentioned above. Leave all your math in seconds during the calculations. A year can be 365 or 366 days, but it's always going to be the same number of seconds. As for a month, don't think of it in days (which can vary), think of 1 month as 1/12 of a year.

Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Preben
AGK Studio Developer
20
Years of Service
User Offline
Joined: 30th Jun 2004
Location:
Posted: 2nd Oct 2018 11:37 Edited at: 2nd Oct 2018 11:38
Cant you just do like this, or did i misunderstood the question ?
if you want it the other way around "future" just check if ... unix > unixfrom ... you get what i mean.

Subscribe and checkout great AppGameKit video's here: Videos click here
Latest GameGuru Loader news: News click here
Get GameGuru Loader PBR version here: Steam click here
best regards Preben Eriksen,
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 2nd Oct 2018 22:42
GetUnixDay/Month/Year will return the Day(1-31) Month(1-12) and Year of the date. Not the Days/Months and Years
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 3rd Oct 2018 00:01
"A year can be 365 or 366 days but it's always going to be the same number of seconds"

Am I missing something here? 365 days is 31536000 seconds, 366 days is 31622400 seconds.

Anyway I assume what you are making is a count down app - in which case they tend to take the days in while months and add them the the days in the current part month. So for example, if today (03/10) I set a countdown for 31st December the app I have on my phone right now adds 31 days for December, 30 days for November and then the difference to the end of October, so 28 days. So in days it would just say 89 days. Or it would literally just say 2 months and X days. I think you're massively over complicating it by converting it to seconds in totality maybe?
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Oct 2018 13:48
1 year is technically 365.256 days, so for 3 years it's 365 then 366 every 4th year (leap) by our calendar. So we're technically a 1/4 to 3/4 of a day behind most years. If you simply break down a year into exact seconds, and take 1/12 of that to represent a month, you get the truest value.

In other words, our calendar has a different number of days depending on the year but a year technically contains the same number of seconds regardless. The leap year just makes up for the lost time our calendar truncates. I suppose I should have said calendar year versus a celestial year.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 3rd Oct 2018 13:53
Em......literally disagree with that. I agree that we use a leap year to account for the difficulty, but in no date measurement EVER would you split it down across all four. So I get your technicality, but I can't think of any single practical application where you would door as you say. If your working with dates, by default you would use the format of the dates, which is the correct years left.

So basically, a count down timer would never say "1.0028 years, four months left" etc.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 5th Oct 2018 00:40
I'm not saying it would return a fractional year, but converting it all to seconds makes it easier to work with. If you had 1.0028 years, you'd say 1 year 1 day 32 minutes and 39 seconds.

I don't know man, dates are weird math. I tested my results with a few websites and get the same results. Do the math in seconds but convert it when you give it back to the user.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 5th Oct 2018 10:44
I wonder if there's a difference in outcome.

I would do it in reverse: take the current second, then the difference to the next whole minute. Then the current minute, then the difference to the next whole hour. Then the current hour to the next whole day etc.

I guess that's not really the relevant part, as be either method your gonna hit a snag converting back where a leap year is involved, if you need to account that far into the future.....in either scenario raw maths inst going to give you the correct result I don't think.

That's said, any date is just an incrementing number, read in chunks.

Would be good to see the final solution decided upon.
Dybing
13
Years of Service
User Offline
Joined: 12th Sep 2011
Location: Bergen, Norway
Posted: 5th Oct 2018 13:20
Did something similar some months back as a little challenge to myself a weekend I was bored...

It'll find number of days from today and back to when you were born. Though it isn't entirely accurate - it may be a day off with certain dates. Just some dates for some reason. Not bothered to find where the flaw is, as I grew bored with it, though I suspect it is lurking in the leap-year calculation.

Login to post a reply

Server time is: 2024-11-23 16:22:52
Your offset time is: 2024-11-23 16:22:52