Moment Timezone弃用警告咨询:非标准日期格式报错修复
Hey there! Let's get that deprecation warning sorted out quickly. Here's what's going on and how to fix it:
The Root Cause
Your current code includes an unnecessary extra step that triggers the warning:
var viewValue = "GMT"; return moment(moment().tz(viewValue).format('LLL'));
When you call .format('LLL'), you're converting the moment object into a localized human-readable string (like "Jan 1, 2024 12:00 PM")—this isn't a standard RFC2822 or ISO date format that Moment.js can reliably parse. Passing this string back to moment() forces it to fall back to the native JavaScript Date() constructor, which is inconsistent across browsers and versions, hence the warning.
The Fix
You don't need to format the moment object just to re-parse it. The moment().tz(viewValue) call already returns a valid Moment.js object representing the current time in the GMT timezone. Just return that directly:
var viewValue = "GMT"; return moment().tz(viewValue);
If You Need the Formatted String (Optional)
If your actual goal was to return the 'LLL' formatted string instead of a moment object, skip the re-parsing step entirely and return the formatted string directly:
var viewValue = "GMT"; return moment().tz(viewValue).format('LLL');
This eliminates the deprecation warning because you're no longer asking Moment.js to parse a non-standard date string.
内容的提问来源于stack exchange,提问作者Rahul Pawar

