Your date may be a numeric value or String data as a JSON response to a Server request. Now having that value converted to a date has its advantages. All you have to do is check the object if it has the getMonth() method. If it does that means its already a date object otherwise just use the parser along the date format. Here is how to do it
Ext.Date.parse( String input, String format, [Boolean strict] ) : Date
Parses the passed string using the specified date format. Note that this function expects normal calendar dates, meaning that months are 1-based (i.e. 1 = January). Keep in mind that the input date string must precisely match the specified format string in order for the parse operation to be successful (failed parse operations return a null value).
Examples:
Some of the currently supported date formats ...
1
2
3
4
5
6
7
8
9
| function convertMyDate(value) { //check if the input value is already a date if (!value.getMonth){ //if not a date then convert it to date //specify the format, so if the value is 20120229 then use Ymd format value = Ext.Date.parse(value, 'Ymd' ); } return value; } |
Ext.Date.parse( String input, String format, [Boolean strict] ) : Date
Parses the passed string using the specified date format. Note that this function expects normal calendar dates, meaning that months are 1-based (i.e. 1 = January). Keep in mind that the input date string must precisely match the specified format string in order for the parse operation to be successful (failed parse operations return a null value).
Examples:
1
2
| myDate = Ext.Date.parse( "2012-02-28" , "Y-m-d" ); myDate = Ext.Date.parse( "2012-01-03 5:43:21 PM" , "Y-m-d g:i:s A" );
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| Format Description Example returned values ------ ----------------------------------------------------------------------- ----------------------- d Day of the month, 2 digits with leading zeros 01 to 31 D A short textual representation of the day of the week Mon to Sun j Day of the month without leading zeros 1 to 31 l A full textual representation of the day of the week Sunday to Saturday N ISO-8601 numeric representation of the day of the week 1 (for Monday) through 7 (for Sunday) S English ordinal suffix for the day of the month, 2 characters st, nd, rd or th. Works well with j w Numeric representation of the day of the week 0 (for Sunday) to 6 (for Saturday) z The day of the year (starting from 0) 0 to 364 (365 in leap years) W ISO-8601 week number of year, weeks starting on Monday 01 to 53 F A full textual representation of a month, such as January or March January to December m Numeric representation of a month, with leading zeros 01 to 12 M A short textual representation of a month Jan to Dec n Numeric representation of a month, without leading zeros 1 to 12 t Number of days in the given month 28 to 31 L Whether it's a leap year 1 if it is a leap year, 0 otherwise. o ISO-8601 year number (identical to (Y), but if the ISO week number (W) Examples: 1998 or 2004 belongs to the previous or next year, that year is used instead) Y A full numeric representation of a year, 4 digits Examples: 1999 or 2003 y A two digit representation of a year Examples: 99 or 03 a Lowercase Ante meridiem and Post meridiem am or pm A Uppercase Ante meridiem and Post meridiem AM or PM g 12-hour format of an hour without leading zeros 1 to 12 G 24-hour format of an hour without leading zeros 0 to 23 h 12-hour format of an hour with leading zeros 01 to 12 H 24-hour format of an hour with leading zeros 00 to 23 i Minutes, with leading zeros 00 to 59 s Seconds, with leading zeros 00 to 59 |
when i am trying to parse "Sun Nov 19 00:00:00 IST 2017" getting null value
ReplyDeletei am getting same error , i just want to display only 1- 12 hours
DeleteIt was really a nice post and I was really impressed by reading this keep updating Angular Training
ReplyDeleteReact js Online Training
NodeJS Course
ReplyDeleteGet inspired by your blog. Keep doing like this....
Spoken English Classes in Bangalore
Spoken English Classes in Pune
spoken english centre in Hyderabad
English Speaking Course in Gurgaon
Nice blog! Thanks for sharing this valuable information
ReplyDeleteIELTS Coaching in Hyderabad
IELTS Coaching in Bangalore
IELTS Coaching in Pune
IELTS Coaching in Gurgaon
IELTS Coaching in Delhi
This comment has been removed by the author.
ReplyDeleteThanks for sharing this information, this is useful to me...
ReplyDeleteServices and package prices may vary depends on your business needs and volume of transactions.
QuickBooks ProAdvisor
payroll processing
Nice Article. Thanks for sharing
ReplyDeleteContact us:
Locksmith Melbourne,
Melbourne, VIC-3000,
Australia.
Phone: 03 9464 1230
eMail: info@locksmithmelbourne.net
Web: https://locksmithmelbourne.net/
This comment has been removed by the author.
ReplyDeleteThis post is so helpfull and informative.keep updating with more information...
ReplyDeleteAngular JS Framework
AngularJS Concepts
ReplyDeleteGreat blog with good information.
MSBI Training in Chennai
MSBI Online Training
Nciecacont-pu Irla Burns Here
ReplyDeleteboatratealin
Ujectiob-bo David Townes Coolutils Total CSV Converter 4.1.1.33
ReplyDeleteSpeedify
MSI Afterburner
ArtCAM
fitugwardvirb