البرمجة
كيفية الحصول على قائمة المناطق الزمنية باستخدام moment-timezone
07/03/2024آخر تحديث: 07/03/2024
2 أقل من دقيقة
To get the list of all available time zones using moment-timezone in Node.js and format them as “(GMT offset) timezone”, you can use the following approach:
javascriptvar moment = require('moment-timezone');
var timeZones = moment.tz.names().map(function(zone) {
var offset = moment.tz(zone).utcOffset() / 60;
var offsetString = offset >= 0 ? '+' + offset : offset.toString();
return '(GMT ' + offsetString + ':00) ' + zone;
});
console.log(timeZones);
This code snippet will give you an array of time zones formatted as you specified. It calculates the GMT offset for each time zone using moment.tz(zone).utcOffset()
and formats it along with the time zone name.
مقالات ذات صلة
المزيد من المعلومات
لا توجد معلومات إضافية حول كيفية الحصول على قائمة جميع المناطق الزمنية المتاحة باستخدام moment-timezone في Node.js.