Solved

PHP - converting a date/time value to UTC

Posted on 2009-05-20
8
2,425 Views
Last Modified: 2013-12-13
How would I convert the following date/time object to UTC?

$opening_time = date('Y-m-d H:i:s', time());

- Yvan
0
Comment
Question by:egoselfaxis
  • 3
  • 3
  • 2
8 Comments
 
LVL 7

Expert Comment

by:ycTIN
ID: 24433559
echo $opening_time = date(DATE_RFC822);
0
 
LVL 7

Expert Comment

by:ycTIN
ID: 24433580

DATE_ATOM (string)
Atom (example: 2005-08-15T15:52:01+00:00) 
 
DATE_COOKIE (string)
HTTP Cookies (example: Monday, 15-Aug-05 15:52:01 UTC) 
 
DATE_ISO8601 (string)
ISO-8601 (example: 2005-08-15T15:52:01+0000) 
 
DATE_RFC822 (string)
RFC 822 (example: Mon, 15 Aug 05 15:52:01 +0000) 
 
DATE_RFC850 (string)
RFC 850 (example: Monday, 15-Aug-05 15:52:01 UTC) 
 
DATE_RFC1036 (string)
RFC 1036 (example: Mon, 15 Aug 05 15:52:01 +0000) 
 
DATE_RFC1123 (string)
RFC 1123 (example: Mon, 15 Aug 2005 15:52:01 +0000) 
 
DATE_RFC2822 (string)
RFC 2822 (Mon, 15 Aug 2005 15:52:01 +0000) 
 
DATE_RFC3339 (string)
Same as DATE_ATOM (since PHP 5.1.3) 
 
DATE_RSS (string)
RSS (Mon, 15 Aug 2005 15:52:01 +0000) 
 
DATE_W3C (string)
World Wide Web Consortium (example: 2005-08-15T15:52:01+00:00) 

Open in new window

0
 
LVL 7

Expert Comment

by:szewkam
ID: 24433693
Something like this?
$opening_time = date('Y-m-d H:i:s', strtotime($opening_time)-date("Z"));

Open in new window

0
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.

 

Author Comment

by:egoselfaxis
ID: 24433761
>> echo $opening_time = date(DATE_RFC822);

This generates the incorrect date/time object for me.

When I ran the script, . it generated the following:

Wed, 20 May 09 10:28:43 -0600

However, the UTC time shoud have actually been 04:28 pm.

I'm currently in EST time zone, .. and it appears that the UTC time offset is merely 4 hrs.

How can I adapt my existing date/time object by adding 4 hrs to the time?

$opening_time = date('Y-m-d H:i:s', time());

 I'm aware of how to do this with the date, .. though I'm not sure if it's possbile to do this with times (and if it intelligentlly increments the date +1 when necessary, etc). Please advise.

- Yvan



 
0
 

Author Comment

by:egoselfaxis
ID: 24433775
>> $opening_time = date('Y-m-d H:i:s', strtotime($opening_time)-date("Z"));

This renders the date as "1969-12-31 23:00:00 " -- which is also incorrect
0
 
LVL 7

Expert Comment

by:szewkam
ID: 24433884
i show how to convert existing $opening_time to UTC ;)
Try this:
$opening_time = date('Y-m-d H:i:s', time()-date("Z")) ;).
0
 
LVL 7

Accepted Solution

by:
ycTIN earned 500 total points
ID: 24433983
http://www.php.net/manual/en/function.date.php

http://www.php.net/date_default_timezone_set
http://www.php.net/manual/en/timezones.php

//you can put this into config file
date_default_timezone_set("America/New_York");
 
echo $opening_time = date('Y-m-d h:i:s a', time());

Open in new window

0
 

Author Comment

by:egoselfaxis
ID: 24434925
>> date_default_timezone_set("America/New_York");

I set this to .. date_default_timezone_set("UTC"); ... right before my variable assignment, and that seemed to do the trick.  Thanks!

- yg
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
PHP strings vs array errors 13 33
Number of hours between date in DB and now 8 21
What's wrong with this PDO query? 5 27
mysql query for sum() 3 28
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 …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
The viewer will learn how to count occurrences of each item in an array.

828 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