How to identify date string and date

In CF10, how can I determine if an object is a date string or a date object?

myDateString = '2015-05-05';
myDateObject = createDate( 2015, 5, 5 );

I tried isDate (), isValid ('date'), isValid ('string'). All these functions give the same answers ("YES") for both variables. However, it lsParseDateTime( myDateObject )throws an error, so I need to check the type of the object before I run the lsParseDateTime function on it.

ps. parseDateTime( myDateObject )works fine, which makes me wonder if lsParseDateTime should throw an error. In Railo 4.2, it lsParseDateTime( myDateObject )works fine.

+4
source share
2 answers

You can use the fact that all CFML objects are also Java objects and use Java methods:

myDateString = '2015-05-05';    
myDateObject = createDate( 2015, 5, 5 );    

writeOutput(myDateString.getClass().getName());    
writeOutput("<br>");    
writeOutput(myDateObject.getClass().getName());    

:

java.lang.String
coldfusion.runtime.OleDateTime
+11

isInstanceOf (obj, "typeName" ) coldfusion.runtime.OleDateTime java.util.Date ():

   isInstanceOf(myDateObject, "coldfusion.runtime.OleDateTime");    
   isInstanceOf(myDateObject, "java.util.Date"); 

IsInstanceOf , . , , .

Update:

, lsParseDateTime

POV. , LSParseDateTime " Java " "... , ". ParseDateTime , , (). CF , , {ts '2015-05-18 16:06:10'}. "" . , ParseDateTime , .

, CF , , , - , LSParseDateTime, , .

+2

All Articles