0

I have a date field saved as Unix timestamp with site's timezone. I have a new local timezone field with limited options so that administrator users can enter the event date with the local timezone where that event actually happen.

I have created a view for the next immediate event by comparing the relative date. Using the result date, I need to display the counter like functionality,
for example 1 day, 30 hours, 15 minutes, 20 seconds.

To make a counter I am using the following JavaScript in a view field template.

var event_date = <?php  echo $output;?>;
var countdown = new Date (event_date).getTime();
var local_time = new Date().getTime();
var distance = countdown - local_time; 
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);

It works, but only for the site's timezone. How do I show the date in the timezone entered for the event?

  • If acceptable to your case, to avoid the whole mess-up with multiple time-zones, you could set website's timezone to UTC and prevent users from setting their own timezones. – AltaGrade Apr 2 '18 at 19:20
  • The site is on live so its kind of change request. so i cant make any major change as u said about to change the site timezone – Vinodhini Apr 3 '18 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.