“Deprecation warning: moment construction falls back to js Date” when trying to convert RFC2822 date in moment.js
To get rid of the warning, you need to either:
Pass in an ISO formatted version of your date string:
moment('2014-04-23T09:54:51');
Pass in the string you have now, but tell Moment what format the string is in:
moment('Wed, 23 Apr 2014 09:54:51 +0000', 'ddd, DD MMM YYYY HH:mm:ss ZZ');
Convert your string to a JavaScript Date object and then pass that into Moment:
moment(new Date('Wed, 23 Apr 2014 09:54:51 +0000'));
The last option is a built-in fallback that Moment supports for now, with the deprecated console warning. They say they won't support this fallback in future releases. They explain that using new Date('my date')
is too unpredictable.
Deprecation warning: moment construction falls back to js Date
You need to tell moment how to parse your date format, like this:
var parsedDate = moment.utc("150423160509", "YYMMDDHHmmss");
var a = parsedDate.tz("Asia/Taipei");
// I'm assuming you meant HH:mm:ss here
console.log( a.format("YYYY-MM-DD HH:mm:ss") );
Deprecation warning: moment construction falls back to js Date in nodejs
Try specifying the format as a second parameter, so that the library doesn't need to guess the actual format:
var m = moment("2016-5-20 17:25:45", "YYYY-M-D HH:mm:ss");
var s = m.toISOString();
Sources:
http://momentjs.com/docs/#/parsing/
https://github.com/moment/moment/issues/1407
momentjs deprecation warning
Try this :
let thisDate = moment(new Date().toISOString()).format("YYYY-MM-DD")
or better
let thisDate = moment().format('YYYY-MM-DD')
Explication :
new Date()
Thu Oct 19 2017 17:50:06 GMT+0200 (Paris, Madrid (heure d’été))
==> depending of local browser and browser implementation
new Date().toISOString()
"2017-10-19T15:50:31.690Z"
==> fixed format, it's always safe ! ;-)
Moment.JS deprecation warning
Since your input is not in ISO 8601 recognized format, neither in RFC 2822 format, you have to use moment(String, String)
.
Here a working sample:
var created_at = 'Mon Oct 16 10:31:26 +0000 2017';var localTime = moment.utc(created_at, 'ddd MMM DD HH:mm:ss ZZ YYYY');localTime = localTime.calendar();console.log(localTime);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
How to parse given date string using moment.js?
Just use pattern as second parameter in moment function
var testDate = moment(dateString, pattern)
more here in the docs: http://momentjs.com/docs/#/parsing/string-format/
Deprecation warning in Moment.js - Not in a recognized ISO format
Check out all their awesome documentation!
Here is where they discuss the Warning Message.
String + Format
Warning: Browser support for parsing strings is inconsistent. Because there is no specification on which formats should be supported, what works in some browsers will not work in other browsers.
For consistent results parsing anything other than ISO 8601 strings, you should use String + Format.
moment("12-25-1995", "MM-DD-YYYY");
String + Formats (multiple formats)
If you have more than one format, check out their String + Formats (with an 's').
If you don't know the exact format of an input string, but know it could be one of many, you can use an array of formats.
moment("12-25-1995", ["MM-DD-YYYY", "YYYY-MM-DD"]);
Please checkout the documentation for anything more specific.
Timezone
Checkout Parsing in Zone, the equivalent documentation for timezones.
The moment.tz constructor takes all the same arguments as the moment constructor, but uses the last argument as a time zone identifier.
var b = moment.tz("May 12th 2014 8PM", "MMM Do YYYY hA", "America/Toronto");
EDIT
//...
var dateFormat = "YYYY-M-D H:m"; //<-------- This part will get rid of the warning.
var aus1_s, aus2_s, aus3_s, aus4_s, aus5_s, aus6_s, aus6_e;
if ($("#custom1 :selected").val() == "AU" ) {
var region = 'Australia/Sydney';
aus1_s = moment.tz('2016-9-26 19:30', dateFormat, region);
aus2_s = moment.tz('2016-10-2 19:30', dateFormat, region);
aus3_s = moment.tz('2016-10-9 19:30', dateFormat, region);
aus4_s = moment.tz('2016-10-16 19:30', dateFormat, region);
aus5_s = moment.tz('2016-10-23 19:30', dateFormat, region);
aus6_s = moment.tz('2016-10-30 19:30', dateFormat, region);
aus6_e = moment.tz('2016-11-5 19:30', dateFormat, region);
} else if ($("#custom1 :selected").val() == "NZ" ) {
var region = 'Pacific/Auckland';
aus1_s = moment.tz('2016-9-28 20:30', dateFormat, region);
aus2_s = moment.tz('2016-10-4 20:30', dateFormat, region);
aus3_s = moment.tz('2016-10-11 20:30', dateFormat, region);
aus4_s = moment.tz('2016-10-18 20:30', dateFormat, region);
aus5_s = moment.tz('2016-10-25 20:30', dateFormat, region);
aus6_s = moment.tz('2016-11-2 20:30', dateFormat, region);
aus6_e = moment.tz('2016-11-9 20:30', dateFormat, region);
}
//...
Related Topics
Angularjs - Any Way for $Http.Post to Send Request Parameters Instead of JSON
Check If Every Element in One Array Is in a Second Array
Casting Plain Objects to Class Instances in JavaScript
How to Access Local Scope Dynamically in JavaScript
Why Does !New Boolean(False) Equals False in JavaScript
Tool to Unminify/Decompress JavaScript
Prevent Requirejs from Caching Required Scripts
Using JavaScript to Display a Blob
Chrome, JavaScript, Window.Open in New Tab
Failed to Execute 'Postmessage' on 'Domwindow': Https://Www.Youtube.Com !== Http://Localhost:9000
How to Parse JSON to Receive a Date Object in JavaScript
Adding Custom Functions into Array.Prototype
Onclick Not Working on Mobile (Touch)
Do You Ever Need to Specify 'Javascript:' in an Onclick
How to Load Local Script Files as Fallback in Cases Where Cdn Are Blocked/Unavailable