?
Solved

convert timestamp to date time in new york

Posted on 2011-09-23
10
Medium Priority
?
910 Views
Last Modified: 2012-05-12
convert timestamp to date time in new york
0
Comment
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 1000 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 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1000 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 111

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

7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

Question has a verified solution.

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

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.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…
Suggested Courses

764 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