Solved

convert timestamp to date time in new york

Posted on 2011-09-23
10
859 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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…

743 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

14 Experts available now in Live!

Get 1:1 Help Now