البرمجة

كيفية الحصول على قائمة المناطق الزمنية باستخدام moment-timezone

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:

javascript
var 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.

مقالات ذات صلة

زر الذهاب إلى الأعلى

هذا المحتوى محمي من النسخ لمشاركته يرجى استعمال أزرار المشاركة السريعة أو تسخ الرابط !!