IT박스

순간 js의 지원 중단 경고-인식 된 ISO 형식이 아님

itboxs 2020. 7. 6. 08:07
반응형

순간 js의 지원 중단 경고-인식 된 ISO 형식이 아님


현재 제공된 값이 인식 된 ISO 형식이 아니라는 경고가 표시됩니다. 오늘 모멘트 기능으로 변수를 변경했지만 여전히 작동하지 않습니다.

경고 오류는 다음과 같습니다.

지원 중단 경고 : 제공된 값이 인식 된 ISO 형식이 아닙니다. 모멘트 구성은 js Date ()로 돌아가며 모든 브라우저와 버전에서 신뢰할 수는 없습니다. ISO가 아닌 날짜 형식은 사용하지 않는 것이 좋으며 향후 주요 릴리스에서 제거 될 예정입니다. 자세한 내용은 http://momentjs.com/guides/#/warnings/js-date/참조하십시오 . 인수 : [0] _isAMomentObject : true, _isUTC : true, _useUTC : true, _l : 정의되지 않음, _i : 2016-9-26 19:30, _f : 정의되지 않음, _strict : 정의되지 않음, _locale : [object Object]

 var entryDate = new Date();
 var currentDate = entryDate.getDate();

        function between(x,min,max) { 
            return x.valueOf() >= min.valueOf() && x < max.valueOf();
        };

        $("#custom1").change(function(){
            if ($("#custom1 :selected").val() == "AU" ) {
                var keyword = "";

                var aus1_s = moment.tz('2016-9-26 19:30', 'Australia/Sydney');              
                var aus2_s = moment.tz('2016-10-2 19:30', 'Australia/Sydney');              
                var aus3_s = moment.tz('2016-10-9 19:30', 'Australia/Sydney');                  
                var aus4_s = moment.tz('2016-10-16 19:30', 'Australia/Sydney');                 
                var aus5_s = moment.tz('2016-10-23 19:30', 'Australia/Sydney');
                var aus6_s = moment.tz('2016-10-30 19:30', 'Australia/Sydney');
                var aus6_e = moment.tz('2016-11-5 19:30', 'Australia/Sydney');
            } 

            else if ($("#custom1 :selected").val() == "NZ" ) {
                var aus1_s =  moment.tz('2016-9-28 20:30', 'Pacific/Auckland');
                var aus2_s =  moment.tz('2016-10-4 20:30', 'Pacific/Auckland');
                var aus3_s =  moment.tz('2016-10-11 20:30', 'Pacific/Auckland');
                var aus4_s =  moment.tz('2016-10-18 20:30', 'Pacific/Auckland');
                var aus5_s =  moment.tz('2016-10-25 20:30', 'Pacific/Auckland');
                var aus6_s =  moment.tz('2016-11-2 20:30', 'Pacific/Auckland');
                var aus6_e =  moment.tz('2016-11-9 20:30', 'Pacific/Auckland');
            }

            else {
                $("#entryEquals").val("");
                return false;
            }

           var today = moment();

            switch (true) {
                case between (today, aus1_s, aus2_s):
                keyword = "RElYT04=";
                break;

                case between (today, aus2_s, aus3_s):
                keyword = "QlJJREU=";
                break;

                case between (today, aus3_s, aus4_s):
                keyword = "U1lETkVZ";
                break;

                case between (today, aus4_s, aus5_s):
                keyword = "R1JPT00=";
                break;

                case between (today, aus5_s, aus6_s):
                keyword = "V0VERElORw==";
                break;

                case between (today, aus6_s, aus6_e):
                keyword = "VExD";
                break;

                default:
                $("#entryEquals").val("");
                break;
            }

        $("#entryEquals").val(keyword);

        });

멋진 문서를 모두 확인하십시오!

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);
}
//...

Doing this works for me:

moment(new Date("27/04/2016")).format

I ran into this error because I was trying to pass in a date from localStorage. Passing the date into a new Date object, and then calling .toISOString() did the trick for me:

const dateFromStorage = localStorage.getItem('someDate');
const date = new Date(dateFromStorage);
const momentDate = moment(date.toISOString());

This suppressed any warnings in the console.


use moment in your function like this

 moment(new Date(date)).format('MM/DD/YYYY')

This answer is to give a better understanding of this warning

Deprecation warning is caused when you use moment to create time object, var today = moment();.

If this warning is okay with you then I have a simpler method.

Don't use date object from js use moment instead. For example use moment() to get the current date.

Or convert the js date object to moment date. You can simply do that specifying the format of your js date object.

ie, moment("js date", "js date format");

eg:

moment("2014 04 25", "YYYY MM DD");

(BUT YOU CAN ONLY USE THIS METHOD UNTIL IT'S DEPRECIATED, this may be depreciated from moment in the future)


Parsing string with moment.js.

const date = '1231231231231' //Example String date
const parsed = moment(+date);

참고URL : https://stackoverflow.com/questions/39969570/deprecation-warning-in-moment-js-not-in-a-recognized-iso-format

반응형