0

I am using a timestamp attribute to display the current time and date on my page.

Is it possible to display it in a particular time zone? I want to display it in ZULU timezone which is static and does not observe daylight saving time.

<script>
import Logger from './Logger'

export default {
  name: 'Navbar',
  components: {
    Logger
  },
  data: {
    timestamp: ""
  },
  created() {
    setInterval(this.getNow, 1000);
  },
  methods: {
    getNow: function() {
      const today = new Date();
      const date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
      const time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds() + " - " +  "ZULU";
      const dateTime = date +' '+ time;
      this.timestamp = dateTime;
    }
  }
}
</script>
aynber
  • 22,380
  • 8
  • 50
  • 63
Woop
  • 61
  • 9

1 Answers1

0

I believe this is not a Vue question, but a regular JavaScript question because Date() is built into JavaScript. When you first create the Date, it uses the time zone of the host system that created it. Then after the date is created, you can convert it to the ZULU time zone using the builtin toLocaleString function, as shown in this answer: Convert date to another timezone in JavaScript

Here is more information about toLocaleString and how it can be used to convert time zones: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString