Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Date_Time Stamp comparisons

Contributor ,
Oct 30, 2015 Oct 30, 2015

Hi all,

What is the best way to do Date_Time Stamp comparisons with

1 - a server in CA  ---- php would be to set date_default_timezone_set("America/Los_Angeles")

and

2 -  any persons browser anywhere they are in the world?

I imagine it would be best to convert each Date_Time Stamp to GMT somehow - but not quite sure the best way to do this

726
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Oct 30, 2015 Oct 30, 2015

PHP handles timezone differences. Note that you need to take into account the server timezone, database, and the specific locales.

Here is a nice little article that discusses it:

https://blog.serverdensity.com/handling-timezone-conversion-with-php-datetime/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 31, 2015 Oct 31, 2015

The article that Rob points to is very useful. If you're interested in an in-depth exploration of working with dates, times, and time zones in PHP, you might want to take a look at my PHP Date and Time Essential Training course on lynda.com. I devote a whole chapter to working with time zone differences. Viewing the course requires a subscription to lynda.com, but you can get a 10-day free trial. There are also a couple of unlocked videos in the course to give you an indication of what's on offer.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Oct 31, 2015 Oct 31, 2015

David, I just looked at your DateTime tutorial on lynda.com and it is indeed an in-depth review of DateTime and its methods.

I find the IntlDateFormatter() class to be very useful for international applications. For anyone unfamiliar with it, this class provides language-specific formatting, so you can, for example, create a weekly calendar that will display the correct days of the week in any of over 100 different languages.

Example:

if ($language_selected=='en'){
$formatter = new IntlDateFormatter($language_selected, IntlDateFormatter::LONG, NULL, 'America/Los_Angeles', NULL, "EEEE, MMMM d, y");
}

$date2 = $formatter->format($enddate);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 31, 2015 Oct 31, 2015

Rob Hecker2 wrote:

David, I just looked at your DateTime tutorial on lynda.com and it is indeed an in-depth review of DateTime and its methods.

Thank you.

Rob Hecker2 wrote:

I find the IntlDateFormatter() class to be very useful for international applications. For anyone unfamiliar with it, this class provides language-specific formatting, so you can, for example, create a weekly calendar that will display the correct days of the week in any of over 100 different languages.

Wow. You have just blown my mind. When creating the course for lynda.com, I wanted to include details of how to format dates in other languages. I knew about strftime(), but it's heavily reliant on the operating system and locale settings, so I eventually decided against covering it. I'll certainly look into IntDateFormatter and the other aspects of intl, which I was completely unaware of.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Oct 31, 2015 Oct 31, 2015

Wow. You have just blown my mind.

Discovering this class has certainly been beneficial to my work. It was not activated on my external server by default though, and whenever easyApache is run it gets bounced out.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 06, 2015 Nov 06, 2015

Thanks Rob & David - so much expertise - WOW!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 06, 2015 Nov 06, 2015
LATEST

Great Idea - will do!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Oct 31, 2015 Oct 31, 2015

2 -  any persons browser anywhere they are in the world?

This part of your question hasn't been addressed. To a certain extent you can identify the locale a web visitor is in from the ip address they are connecting from. I don't know of any service that maps ip addresses to time zones.

I live in a rural area where the internet connection is via satellite. From my ip address, this makes it appear that I am in the Central (US) timezone whereas I am actually in the Pacific Timezone. Two hours difference.

. . .so if you need serious timezone accuracy, you may want to display the "reported" timezone on the screen,with the ability for the user to change it as necessary.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines