Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

convert timestamp to date time in new york

Posted on 2011-09-23
10
Medium Priority
?
920 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses four methods for overlaying images in a container on a web page
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

636 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