Solved

convert timestamp to date time in new york

Posted on 2011-09-23
10
866 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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
 
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 109

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 109

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

825 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