简体   繁体   中英

How to convert date time string in formatted date time in extjs

I have a string of Date and Time ("2017-11-29 11:08:43" YYYY-MM-DD hh:mm:ss) like this. I want to convert it into "29-11 11:08"(DD-MM hh:mm) format. I tried it using below code. But not get any success. have you any solution?

convert: function (idleFrom) {
            var date = Ext.Date.parse(idleFrom, "Y-m-d");
            return date;
        }

first change your string into date format using

var dt = new Date(idleFrom)

than change into you required format using

Ext.Date.format(dt, 'm/d/Y');

follw this link for more format

Hope it will work :)

If you have a string, and want it reformatted, you have to parse the string into a JS date object first, and then format the JS date object into the string representation you need:

var date = Ext.Date.parse("2017-11-29 11:08:43", "Y-m-d H:i:s")
var str = Ext.Date.format(date, "m/d/Y")

Please note that Ext.Date.parse is really picky regarding the format identifier. If the matching between the format identifier and the input string's format is not 100%, your date will be null .

Eg Ext.Date.parse("2017-11-29 11:08:43", "Ymd H:i") will be null because the seconds are in the date string, but missing from the format identifier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM