- Oct 14, 2001
- 2,492
- 3
- 81
Originally posted by: DnetMHZ
I guess I should have asked if you needed to do this only once or programmatically.![]()
Originally posted by: Jzero
This is a very elementary conversion problem. I'll give you a hint: 31557600 seconds in a 365.25-day year.
Originally posted by: Armitage
Originally posted by: Jzero
This is a very elementary conversion problem. I'll give you a hint: 31557600 seconds in a 365.25-day year.
It's not quite so elementary when you roll leap years, leap seconds, time zones, daylight savings time, etc. into it.
Time keeping is a messy business - best to use the library functions (ctime, asctime, localtime, gmtime, etc.)
Originally posted by: Jzero
Originally posted by: Armitage
Originally posted by: Jzero
This is a very elementary conversion problem. I'll give you a hint: 31557600 seconds in a 365.25-day year.
It's not quite so elementary when you roll leap years, leap seconds, time zones, daylight savings time, etc. into it.
Time keeping is a messy business - best to use the library functions (ctime, asctime, localtime, gmtime, etc.)
Yes, you can complicate it as much as you wish, but converting number seconds "after the epoch" to local time is a rudimentary factor-label conversion.
You will obviously assume your own local time zone and DST rules.
It's trivial to figure out how many leap years have occurred since 1970.
Leap seconds, which are added on an as-needed basis, need only be factored in if extreme precision is required, but it is certainly easy enough to look up how many leap seconds have been inserted between 1970 and now (22, all positive).
This isn't timekeeping, it's merely converting measurements.
Re-read the question. Are you familiar with Unix "epoch time?"Originally posted by: Armitage
It's not how many leap years or leap second have occured between 1970 and now, but how many have occured between 1970, and the epoch in question.
Well, basically because I have never seen this question asked outside of beginning programming classes where one is asked to write a program to convert "epoch" time to "normal" time WITHOUT using existing functions. There's plenty of existing methods to make the conversion, but I'm assuming if the question is being asked, it's because those existing methods are off limits, but perhaps I am assuming too muchIt's not all that hard, but there's alot of room to scew it up, so why wouldn't you use the standard library functions?
Originally posted by: Jzero
Re-read the question. Are you familiar with Unix "epoch time?"Originally posted by: Armitage
It's not how many leap years or leap second have occured between 1970 and now, but how many have occured between 1970, and the epoch in question.
You have the current time in number of seconds since January 1, 1970. That date IS the epoch for this particular system, which we can assume to be some unix-like OS. Convert that to "standard" time format.
Issue the command date +%s and you will get something like 1117202362 which represents the number of seconds in local system time (which is why time zone and DST are of no concern) that have passed since January 1, 1970.
Well, basically because I have never seen this question asked outside of beginning programming classes where one is asked to write a program to convert "epoch" time to "normal" time WITHOUT using existing functions. There's plenty of existing methods to make the conversion, but I'm assuming if the question is being asked, it's because those existing methods are off limits, but perhaps I am assuming too muchIt's not all that hard, but there's alot of room to scew it up, so why wouldn't you use the standard library functions?![]()
Originally posted by: Jzero
Issue the command date +%s and you will get something like 1117202362 which represents the number of seconds in local system time (which is why time zone and DST are of no concern) that have passed since January 1, 1970.
You and n0cmonkey are indeed correct that it is UTC/GMT and not local time.Originally posted by: Armitage
Yep I'm familiar with it. But in fact, date +%s returns seconds since Jan 1 1970 UTC, so you do need timezone & DST information to get the current local time.
It is probably most straightforward to just use 365 day years and add a day for each leap year since 1970.In any case, let's try an example...
You may be right. The OP didn't give us much to go by.I think you're assuming to much - I think he was just asking what the existing functions were, not how to roll his own.
Originally posted by: Jzero
You and n0cmonkey are indeed correct that it is UTC/GMT and not local time.Originally posted by: Armitage
Yep I'm familiar with it. But in fact, date +%s returns seconds since Jan 1 1970 UTC, so you do need timezone & DST information to get the current local time.
It is probably most straightforward to just use 365 day years and add a day for each leap year since 1970.In any case, let's try an example...
Anyway, does this mean we are in agreement that it is just a unit conversion not much different from converting inches to miles?![]()
You may be right. The OP didn't give us much to go by.I think you're assuming to much - I think he was just asking what the existing functions were, not how to roll his own.