Stampa
Categoria: PHP
Visite: 2884
Stella inattivaStella inattivaStella inattivaStella inattivaStella inattiva
 

One of my latest experience has been to show the correct date time to russian guys.

In order to manage the right local date for each country I have done the following 3 simple steps:

  1. Store the date in GMT format (Greenwich Mean Time)
  2. Declare the momentJS in my webpage
  3. Use the momentJS function to convert the date

Browser will do a right conversion

 

 

1) Date Time stored as GMT

I use the followin php function

$today = gmdate("Y-m-d H:i:s");  

 

in alternative your can use utc_timestamp, it release the gmt date time

 

SELECT UTC_TIMESTAMP();

 

2) Include the Momentjs in the head/head

<script type="text/javascript" src="https://momentjs.com/downloads/moment.js"></script>

 

3) In the web page I use the moment javascript

moment.utc(params).local().format('DD/MM/YYYY HH:mm')

 

The browser will use the client local time to show the right time zone.

 

 

 - have fun -

DISQUS - Leave your comments here