javascript - Invalid Date for a new Date("YYYY-MM-DDThh:mm:ss"); instanciation -
I am working with Titanium which is a framework for mobile development based on JavaScript.
The 'YYYY-MM-DD HH: mm: ss' format (NightsArray [i] [3] returns a string representing the 'date and time' string in an array present in its cells. Is: 2014-02-20 23: 00:00) as shown later in the console.
Several controllers have been shown for the date () object with this multiple parameters:
var today = new date (); Var Birthday = New Date ("December 17, 1995 03:24:00"); Var Birthday = New Date ("1995-12-17T03: 24: 00"); Var Birthday = New Date (1995, 11, 17); Var Birthday = New Date (1995, 11, 17, 3, 24, 0); So, as you can see the closest constructor of the string of my array, it is 3th:
var birthdays = new date ("1995- 12-17 tet. 3: 24: 00 "); In the following code I will try to format my string in the form "YYYY-MM-DDThh: mm: ss" with some strings and the resulting string (a concatenation) will be generated on the date ( ) Found on the constructor, but I found 'invalid date' as shown in the console log.
Ti.API.error ("+ * /// +++ NIGHT DATE & amp;; Time (string):" + Nightere [I] [3]); Ti.API.error ("+ * /// +++ Night Date and Time Substitutes (0,10):" + Night Other [i] [3] .sbustrate (0, 10)); Ti.API.error ("+ * /// +++ Night Date and Time Substitutes (Strength) (11,10):" + NightArere [i] [3] .Substrect (11,10)); Ti.API.error ("+ * /// +++" + NightsArray [i] [3] .substr (010) + "T" + NightsArray [i] [3] .substr (11,10) ); Var NightDatam = New Date (Night Other [i] [3] .substr (0,10) + "T" + Knights Array [i] [3]. Siebustre (11,10)); Tiwari API. Terror ("+ * /// +++ Current Date Night Date (Date:" + Night + Time); Var d = new date (); Ti.API.error ("+ * /// +++ CURRENT DATE:" + D); This console is logged:
[error]: + * /// +++ night-time & amp; Time (string): 2014-02-19 23:00:00 [Error]: + * /// +++ Night Date & amp; Time (string) substrate (0,10): 2014-02-19 [error]: + * /// +++ night date & amp; Time (string) substrate (11,10): 23:00:00 [Error]: + * /// +++ 2014-02-19T23: 00: 00 [Error]: + * /// +++ CURRENT Date Date Date Date: Invalid Date [Error]: + * /// +++ Current Date: Mon Feb 17 2014 11:09:09 GMT + 0100 (CET) I have to compare that string from the current date to the end, but now I have to convert that string to a date for the first time, but I wonder why this does not work ..
In Titanium you're trying to parse the UTC date time, when you try to parse the date, this invalid date will be returned. So you need to convert it to a datetime string. You can choose that the string separator characters--, and:, and divide the resulting array objects into the date constructor.
Try the following
function format date (date) {var arr = date.split (/ [-: t] /), // var date from your example = "2012-11-14T06: 57: 36 + 0000"; Date = new date (ARR [0], ARR [1] -1, ARR [2], ARR [3], ARR [4], 00); NewDate = date.toString ("MMMM"); // .. pick additional stuff here)
Comments
Post a Comment