What does the last number in UNIX timestamp mean? - unix

I have a few UNIX timestamps that I've been converting back and forth, and I notice that the last number of the timestamp would change without causing any difference in the date.
For example, if you convert this number to normal date:
1452120848 > 6-1-16 17:54
But if you convert it back:
6-1-16 17:54 > 1452120840
As you can see the last number was changed to a zero. I tried some of the online converters and discovered that the last number could be any number and the date wouldn't change. What does it mean?

The unix time is the time in seconds since 1970.
You don't convert the seconds part of your date, thus it's 'lost' - your numbers may differ by up to 60.
The timestamp of 1452120848 is actually: Wed Jan 6 22:54:08 2016
So you're missing 8 seconds.

The UNIX timestamp gives you the seconds since 1st January 1970 00.00.00 UTC. Since this is seconds and you are just printing up to minutes, the difference is not shown.
However, they are not the same date:
$ date -d#1452120848
Wed Jan 6 23:54:08 CET 2016
$ date -d#1452120840
Wed Jan 6 23:54:00 CET 2016

Related

Scheduling events with changing Time zone

I need help with this scenario:
1) Currently it is summer time. I need to create a time interval for June 9 Monday 6 PM - 7 PM EDT and every week after that until end of 2018. This interval will be for students to schedule appointments with a tutor. The client right now sends that as a request for creating start time at June 9 Mondays 2 PM UTC. (EDT is -4 hours offset) The server creates a start time in db for June 9 2 PM UTC and adds 7 days worth of milliseconds to create recurring
^ this causes an issue because of DST. Let's say it is right now November 5th (which is after daylights saving change). The DB still has Nov 5, 2 PM UTC saved as value. But because my timezone changed, instead of offsetting by 4 hours like I did on June, I offset by 5 hours. So the correct start time is "6 PM session in my timezone" becomes "7 PM my timezone". this is the error
the solution is either of one of two (or combination of both):
1) instead of adding 7 days worth of milisecond, you add 1 week worth of miliseconds depending on the user's timezone Currently, there's no way to extract a person's timezone based on utc offset (-400, which is right now in east coast USA, is also applicable to Canada, Carribeans, South America etc. We need to save a user's timezone as a string, rather than UTC offset count. There is an international standard for timezones)
2) ?? something else

What date format is 636529536000000000?

I have to maintain an ASPX page that increments the date/time by passing a value in the querystring in this format:
636529536000000000 in reference to 31 January 2018
636530400000000000 in reference to 01 February 2018
The url format is: /reservas.aspx?t=636530400000000000
What is this date/time format?
It is the number of ticks where a tick is one hundred nanoseconds or one ten-millionth of a second. The number of ticks is measured since the epoch DateTime.MinValue (12:00:00 midnight, January 1, 0001). For example:
new DateTime(636529536000000000).ToString("F", CultureInfo.InvariantCulture)
outputs:
Wednesday, 31 January 2018 00:00:00
Could be a number of days from certain date, similar to julian date calculation:
https://en.wikipedia.org/wiki/Julian_day#Julian_date_calculation
Potentially incorporating the time as well?
Without details of the code I cant really advise from a provided value.

understanding epoch time to calculate password ageing in unix

my_current_epoch=15684 equivalent time stamp is Thu, 01 Jan 1970 04:21:24
last_password_reset_epoch_time=15547 equivalent time stamp is Thu, 01 Jan 1970 04:19:07
I am not able to understand how difference of these two will give the days since last password reset.
As per my understanding epoch time is denoted in seconds that has elapsed since Jan 1,1970
Can someone please help me understanding this.
man 5 shadow on a Linux box says:
The date of the last password change is given as the number of days since Jan 1, 1970. The password may not
be changed again until the proper number of days have passed, and must be changed after the maximum number
of days. If the minimum number of days required is greater than the maximum number of day allowed, this
password may not be changed by the user.
So, you can find out to within 24 hours when a password was changed by multiplying the value from /etc/shadow by 86400 (the number of seconds in a day — but you didn't need me to tell you that, did you?).
For the values given (bc to the rescue):
15684*86400 = 1355097600
15547*86400 = 1343260800
And:
$ timestamp -u 1355097600 1343260800
1355097600 = Mon Dec 10 00:00:00 2012
1343260800 = Thu Jul 26 00:00:00 2012
$
Timestamp is my program; modern versions of date can handle this too. The -u means 'report in UTC (aka GMT)' rather than in my time zone.
"epoch" value in /etc/shadow = 15684
the seconds in 24 hours (because normally "epoch" value shows in seconds but for some reason (to make compact view, maybe) in /etc/shadow file "epoch" value displays in days, not in seconds) = 24 * 60 * 60 = 86400
And by multipliying these two numbers: 15684 (days) x 86400 (seconds per day); we will get the number 1355097600.
Afterwards, either using Epoch Converter by copy/paste the final result, you can get the date, or
just use date --date #$(( 15684 * 86400 )) command in cli

What timestamp is it?

What timestamp is it?
41056.2752083333 is 14:36 May 27, 2012 GMT+7
41056.2967361111 is 15:07 May 27, 2012 GMT+7
It is from sqlite3 database taken from icq v.7
EDIT
So, thank for the answer.
Here is the func to convert timestamp in icqv7 format to Python's struct_time:
f = lambda x: time.localtime(x*86400-2208988800-172800+3600)
where 2208988800 is the number or seconds between 1 Jan 1900 and 1 Jan 1970,
172800 is the number of seconds in two days,
and 3600 is one hour.
Looks like it's the number of days since the first of January 1900, midnight UTC.
EDIT: Oops - it looks like it's actually two days out, which is very odd. It clearly is a number of days though, as the difference between 41056.2752083333 and 41056.2967361111 is 0.0215277778, which is 31 minutes when taken as "a number of days".
So it looks like you just need to adjust the epoch slightly - with an epoch of December 30th 1899, I get a date/time for the first value of 2012-05-27T06:36:00Z - there's still an hour discrepancy there, but I suspect that may be due to the way you're diagnosing the date/time rather than anything else. Do you have any values in December, for example?

Year 0 gets corrupted

$datetime = new DateTime('0000-00-00 00:00:00');
$date_string = $datetime->format('Y-m-d H:i:s');//-0001-11-30 00:00:00
date gets turned from 0000-00-00 00:00:00 to -0001-11-30 00:00:00
this is obviously wrong, why does this happen, how to fix it?
Should at least return false.
info:
PHP Version 5.2.13-0.dotdeb.1
Linux 2.6.26-2-openvz-amd64 #1 SMP Thu Nov 25 05:14:47 UTC 2010 x86_64
It's sort of correct by definition:
the zero-th day as opposed to the first yields a (hypothetical) minus one day
the zero-th month as opposed to the first yields a (hypothetical) minus one month
Take the (hypothetical) 1st of Jan in the year 0, subtract a month -> 1st of Dec in the year -1.
Subtract a day -> 30th of Nov in the year -1
Alternatively, they could have chosen to fix up the day first, then it'd go like:
1 Jan minus 1d -> 31st of Dec -0001, minus 1mo -> 30th of Nov -0001
The formatter obviously does the bound check to only produce valid dates. (For some definition of ``valid'')

Resources