I want to change the date format for my custom post types from dates to time.

So i starting using this code:

echo get_post_time('g:i A', TRUE, get_the_ID(), TRUE );

It's working successfully but the problem now that it's getting the timezone from the WordPress settings not getting the timezone of the current visitor.

Many sites like facebook or twitter check the timezone of the visitor and get the correct dates depending on his/her location.

How can I do the same?

NOTE: I can do anything to achieve this (Plugins, PHP Scripts) anything.

  • You can't do it with php alone, you should make an ajax call, retrieve the client timezone (i.e: var tzo=(new Date().gettimezoneoffset()/60)*(-1); and write the date info the dom using JS date functions. A second way could be, always with js, set a cookie containing the timezone info and access the cookie via php – Andrea Somovigo Sep 14 '18 at 15:16
  • @AndreaSomovigo okay, I understand you now what's the best WordPress function to can enter the date with the timezone that I get via ajax? In my opinion, the date_i18n function will help me but I will need to make a lot of modifies for it. – John Sep 14 '18 at 18:17

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.