Foreign Time to Local Time

前端 未结 1 1612
北恋
北恋 2021-01-16 13:17

I\'m trying to convert foreign time to Local Time. I\'m getting a date and time in Europe/London. Currently I\'m using moment-timezone to get my code working, h

相关标签:
1条回答
  • 2021-01-16 13:53

    You can use moment.tz to parse your input as Europe/London time and then use the tz function to convert it to Asia/Manila.

    The first parses your input using the given timezone while the latter convert a moment objet to a given timezone.

    Here a working sample:

    // Parse input considering as London tz
    var timeInLondon = moment.tz('2017-06-30T22:10:00', 'Europe/London');
    // Converting input to Manila
    var timeInManila = timeInLondon.tz('Asia/Manila');
    // Show result
    console.log(timeInManila.format('YYYY-MM-DD HH:mm:ss'));
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.11/moment-timezone-with-data-2010-2020.min.js"></script>

    0 讨论(0)
提交回复
热议问题