Solved

convert timestamp to date time in new york

Posted on 2011-09-23
10
860 Views
Last Modified: 2012-05-12
convert timestamp to date time in new york
0
Comment
Question by:rgb192
  • 6
  • 2
  • 2
10 Comments
 
LVL 2

Expert Comment

by:shdwmage
ID: 36589437
I'd love to help, but can you put a bit more detail in it.  Like where are we getting the date stamp from, what format.  What time zone is the server in. Something, anything.
0
 
LVL 2

Expert Comment

by:shdwmage
ID: 36589450
A lot of information about the PHP Date function is available here:
http://php.net/manual/en/function.date.php

Additioinally the newer versions of PHP allow you to specify time zone.
0
 

Author Comment

by:rgb192
ID: 36589460
Unix timestamp 432403200
0
 
LVL 2

Expert Comment

by:shdwmage
ID: 36589532
Found this interesting page on converting epoch time:
http://www.epochconverter.com/

date(output format, epoch); Output format example: 'r' = RFC 2822 date
0
 
LVL 2

Expert Comment

by:shdwmage
ID: 36589728
Knowing the original time zone would help but the following code:
<?php
$test = date("l, F j, Y, g:i a",432403200 ); 
print $test;
?>

Open in new window


yields: Wednesday, September 14, 1983, 12:00 pm
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Accepted Solution

by:
shdwmage earned 250 total points
ID: 36589746
Alright 1 hour is 3600 in EPOCH time.

So say the server was GMT -6 instead of -5:

<?php
$epoch = 432403200;
$epoch = $epoch + 3600;

$test = date("l, F j, Y, g:i a", $epoch ); 
print $test;
?>

Open in new window


Would add the hour and output:
Wednesday, September 14, 1983, 1:00 pm

Hope it helps!
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 36590431
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

Timestamps are the number of seconds since the Unix Epoch, which began at midnight on January 1, 1970 in the GMT timezone.  Thus the timestamp, which is the value returned by time(), is the same everywhere in the world.

The correct code for converting a timestamp to a local time is shown in the code snippet.
http://www.laprbass.com/RAY_temp_rgb192.php
<?php // RAY_temp_rgb192.php
date_default_timezone_set('America/New_York');
echo date('r');

Open in new window

0
 
LVL 2

Expert Comment

by:shdwmage
ID: 36590660
Ray, wouldn't that depend on what his problem actually is?

I read it as converting an already existing date/time stamp to new york time, not the current date time.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 36590682
A datetime value is a string of data, and it is always localized, whether or not localization is shown in the string.  A timestamp is an integer.

In the date() function the second argument, if omitted, is the integer value of time(), which is the same everywhere in the world, even though there are different timezones and there is that International Date Line.  It screws up your medications when you cross it ;-)
http://php.net/manual/en/function.date.php

The date_default_timezone_set() function tells PHP what the localization is for the date() function and some other things, like the strtotime() function.
http://php.net/manual/en/function.date-default-timezone-set.php

See also:
http://php.net/manual/en/timezones.php
0
 

Author Closing Comment

by:rgb192
ID: 36592646
combine these two answers.
thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
calculated column 12 74
Calculate values in an array 18 35
Tableau and Javascript: How to export an array to excel with formatting 11 61
mysql between clause 2 8
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now