im trying to convert a time stamp in seconds from Jan 01 1901 to the current date.
for example,
time stamp 3465468225 translate to a date in 2010. does anyone know of a way to do this in unix/linux? thanks.
In R, it is as simple as this:
> as.POSIXct(3465468225, origin="1901-01-01")
[1] "2010-10-25 15:03:45 CDT"
>
This uses appropriate wrappers around C-level calls gmtime() / localtime() plus time formatting via strftime().
On GNU and POSIX systems you can obtain the date string using seconds since Epoch (1970-01-01 00:00:00 UTC) as:
$ date --date=#1289495920
Thu Nov 11 12:18:40 EST 2010
You should handle the offset since Jan 01 1901 yourself.
Related
I have an array:
my #array = ( "\"Passing\" on Wed 12 Jan 2015 09:19:14 AM PST",
"\"Passing\" on Wed 12 Jan 2015 09:19:25 AM PST",
"\"Test Activation\" on Tues 14 Jan 2015 12:05:14 PM PST",
"\"Run Phase\" on Tues 14 Jan 2015 12:06:14 PM PST",
"\"Test Activation\" on Tues 13 Jan 2015 11:43:12 PM PST")
I want to remove the duplicate string line BUT keep the one that is most recent. So I want it to look like:
my #array = ("\"Passing\" on Wed 12 Jan 2015 09:19:25 AM PST",
"\"Test Activation\" on Tues 14 Jan 2015 12:05:14 PM PST",
"\"Run Phase\" on Tues 14 Jan 2015 12:06:14 PM PST")
I can't think of an easy way to do this... I was thinking about using some regex to compare the strings ( /\".*\"/ ) and have it remove duplicates it finds, but I'm not sure how to deal with the date/time.
Any suggestions are most welcome!
There's several options to parse and compare the dates. Simplest is to use the built in Time::Piece. Use strptime for parsing and compare with $time->epoch.
Unfortunately for you, abbreviated time zone names are ambiguous. PST can mean US Pacific Standard Time or Philippine Standard Time. This may cause strptime's %Z format to choke, YMMV. From my strptime man page...
The %Z format specifier only accepts time zone abbreviations of the local time zone, or the value "GMT". This limitation is because of ambiguity due to of the over loading of time zone abbreviations. One such example is EST which is both Eastern Standard Time and Eastern Australia Summer Time.
You may need to pre-process the date formats and convert them to time zone offsets. You can use Time::Zone for this and its distinctly North American slant.
use Time::Zone;
use Time::Piece;
my $offset = sprintf "%+d", (tz_offset("PST") / 60 / 60);
my $time = Time::Piece->strptime(
"Wed 12 Jan 2015 09:19:14 AM $offset",
"%a %d %b %Y %I:%M:%S %p %z"
);
print $time->datetime, "\n";
print $time->epoch, "\n";
But try %Z first and see if it works.
Extracting the dates is also left as an exercise.
I am working on a little puzzle. I have some timestamps that I know they are timestamps but can't figure out how they are encoded.
3ebf5b89 means 08-October-2013 hour 8 AM but minute I can't provide neither second
3ebd5f09 means 09-October-2013 hour 8 AM Unknown minute/second.
3ea15d09 means 11-October-2013 hour 8 AM Unknown minute/second but before half past hour.
Any ideas on the encoding?
The weird part is that the dates seem to become lower values as days pass.
If I convert to decimal and substract the big date from the small date I get a value witch converted in seconds is around the days between two dates with a 5 hour error per day.
LE:
I managed to get more accurate time stamps :
3ea02d09 - Oct 11th, 2013 at 17:10 (hour:minute)
3ea7ff89 - Oct 12th, 2013 at 14:28
3ea7cf09 - Oct 12th, 2013 at 15:34
it seemed that the timestamp uses Pi as its base to calculate the time!?
3ea7ff89 - 12 October Hour 14 Minute 28
3ea7cf09 - 12 October Hour 15 Minute 34
difference: 12416 ~ 66 minutes
if we divide it by 60 for 60 seconds per minute an after that we divide it by 66 for the minutes difference we get
3.13535353535 that is realy close to Pi.
if we use pi to reverse the formular:
Pi*66*60=12440 thats in the error range of the not delivered seconds in your timestamps.
I wonder those HEX converted to Decimal has some relation to Unix Epoch time :
Those Hex numbers are translating to some valid Dates though different from what you mentioned those are :
Hex 3ebf5b89 = Decimal 1052728201 = Mon, 12 May 2003 08:30:01 GMT
Hex 3ebd5f09 = Decimal 1052598025 = Sat, 10 May 2003 20:20:25 GMT
Hex 3ea15d09 = Decimal 1050762505 = Sat, 19 Apr 2003 14:28:25 GMT
Hex 3ea02d09 = Decimal 1050684681 = Fri, 18 Apr 2003 16:51:21 GMT
Hex 3ea7ff89 = Decimal 1051197321 = Thu, 24 Apr 2003 15:15:21 GMT
Hex 3ea7cf09 = Decimal 1051184905 = Thu, 24 Apr 2003 11:48:25 GMT
I've tried to play around with the binary form of your inputs and using the bitwise XOR (the poor man's cipher) operator between the value and the corresponding UNIX timestamp.
This is what I've got so far:
(1381507800 ^ 0x3ea02d09) = 0110110011111 00000001111 11 010 001
(1381584480 ^ 0x3ea7ff89) = 0110110011111 11010110001 11 101 001
(1381588440 ^ 0x3ea7cf09) = 0110110011111 11010010010 11 010 001
16bits + 2bits stay stable.
The first 13bits plus the last 3bits (which make 16bits if combined) make me think of some kind of rotate shift left.
Please note that my timezone is UTC+1 and thus my UNIX time stamps may not be exact. It would be great if you can get the corresponding timestamps on your system to push this lead further.
I am writing a script in PHP which will convert Numbers file into HTML table, but I can not figure out which format is used for date storage. The date cell tag looks like
<sf:d
sf:s="SFTCellStyle-128"
sf:w="84.074219"
sf:h="14"
sf:cell-date="371397519.99999952" />
so the date must be in sf:cell-date attribute, but I can not figure out how to convert it into human readable format. Any ideas? I have never seen date value as float number.
As written in a comment, it is the number of seconds since 01/01/2001 at 00:00:00. Equipped with that knowledge and because this goes hand in hand with the UNIX Epoch all you need to do is to define and use the offset. It should be compatible with nearly every of the existing PHP date functions and objects, for example with date:
define('CELL_DATE_EPOCH_OFFSET', 978307200);
$sf_cell_date = 371397519.99999952;
echo date('r', CELL_DATE_EPOCH_OFFSET + $sf_cell_date);
The output of this little script is (in my timezone):
Mon, 08 Oct 2012 15:58:39 +0200
I hope this is helpful. 978307200 is the unix timestamp for 01/01/2001 00:00:00 UTC, you can get with PHP for example with the following code-example:
$base = new DateTime('01/01/2001 00:00:00 UTC');
echo $base->getTimestamp(), "\n";
in case that was your problem.
Both strtotime and mktime are outputting an incorrect timestamp and it's driving me mad.
If I add the following strtotime('2012-10-09');
I get 1349701200
Which is actually
Mon, 08 Oct 2012 13:00:00 GMT
I'm using my localhost, running MAMP. I'm assuming it's a server timezone issue, or something, but I don't understand why, or how to fix it.
Any help?
strtotime uses default timezone to interpret the string. If you want different timezone you could specify it explicitly or change it for all calls:
<?php
if (date_default_timezone_get()) {
echo 'date_default_timezone: ' . date_default_timezone_get()."\n";
}
echo strtotime('2012-10-09')."\n"; # default timezone
echo strtotime('2012-10-09 UTC')."\n";
date_default_timezone_set('UTC');
echo strtotime('2012-10-09')."\n";
?>
Output
date_default_timezone: Europe/London
1349737200
1349740800
1349740800
POSIX timestamp counts number of seconds since 1970-01-01 00:00:00 UTC. For example, midnight (00:00) in New York may be 20:00 in UTC at this time of year (the same POSIX timestamp). But 00:00 in UTC and 00:00 in New York correspond to different moments in time (different POSIX timestamps). Local clocks follow the Sun usually (roughly speaking) and even if it is night where you are; the Sun shines somewhere on Earth.
I'm working on a podcast (on-the-road events) that contains future dates and different time zones.
<pubDate>Wed, 14 Nov 2012 19:00:00 EST</pubDate>
<pubDate>Wed, 25 Jul 2012 19:00:00 CDT</pubDate>
<pubDate>Thu, 29 Mar 2012 19:00:00 MDT</pubDate>
When I parse it with PHP4 (note PHP4), using date() and strtotime(), it adjusts the information and outputs it in the current timezone of the server (including daylight saving time changes).
Code...
date("g:ia T", strtotime($item->pubDate));
Example...
<pubDate>Thu, 29 Mar 2012 19:00:00 MDT</pubDate> outputs 8:00pm CDT
The expected output is 7:00pm MDT
Again, I'm using PHP4, so I can't do DateTime()-type stuff.
Basically, I just want it to just return the characters, instead of interpreting the characters. Maybe I shouldn't use date() or strtotime() at all, but I'm not sure of another way to turn Wed into Wednesday, 19:00:00 into 7:00pm, etc.