How to fix cesium timezone?

I would like to fix cesium timezone including the timeline. There is a question that someone asked before. But I did not find the solution. Do you have a better solution now?

I use Windows 10 and latest Chrome.

Hi there,

There’s another thread on this topic here on changing the time zone. Let me know if you still have any questions.

Thanks,

Gabby

Here’s a code snippet for what you’d need to do to change the timezone that’s displayed:

viewer.animation.viewModel.timeFormatter = function(date, viewModel) {
  date = Cesium.JulianDate.toDate(date);
  return `${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
};

This would change the default function to instead display just hours, minutes and seconds (in whatever timezone is set by the browser I think). This is where you could integrate a library like MomentJS (https://momentjs.com/) that’ll format the given date and return the string here.

Here’s a Sandcastle.

Need to change the date as well as the time. At 22:00 PDT Aug 10 it states 22:00 Aug 11. So while it’s using the local time, it’s still using the month/day/year of UTC.

var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
viewer.animation.viewModel.dateFormatter = function(date, viewModel) {
  date = Cesium.JulianDate.toDate(date);
  return `${months[date.getMonth()]} ${date.getDate()} ${date.getFullYear()}`;
};

I also noticed it doesn’t pad a 0 when minutes are less than 10, anyone know of an easy way to pad a 0?