Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

230
Views
show saved utc time in database as invisitor's local lime based on his local time zone

I have a php script that adds a time along with other data in database :

<?php 

$UTC_TIME = gmdate("Y-m-d H:i:s"); //Gives : 2022-01-26 14:11:43

?>

Now, when the webpage is viewed at different locations in different countries. So i want to display the UTC time saved in database in local time of visitor who is accessing the webpage.

For example, if a user access the page from UK, the date time (2022-01-26 14:11:43) should be into converted into UK time (That was at the time, when this data was saved into the database) and displayed.

I searched alot of topics on stackoverflow, but didn't find any working solution. Thanks for your help!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Just add a T and a Z

// $UTC_TIME = gmdate("Y-m-d\TH:i:s\Z"); //Gives : 2022-01-26T14:11:43Z
// const time = "<?=$UTC_TIME ?>";
const time = "2022-01-26T14:11:43Z"; // UTC
console.log(new Date(time).toLocaleString()); // my timezone

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!