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

Date_Time Stamp comparisons

Contributor ,
Oct 30, 2015 Oct 30, 2015

Copy link to clipboard

Copied

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

Views

567

Translate

Translate

Report

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

Copy link to clipboard

Copied

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/

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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);

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Thanks Rob & David - so much expertise - WOW!

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

Great Idea - will do!

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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