datetime - Need clarity on javascript date logic -


i getting false both conditions

localstorage.getitem("dl-visited-date") // "mon oct 07 2013 13:58:18 gmt-0400 (edt)"; currentdate // tue oct 08 2013 14:18:26 gmt-0400 (edt) currentdate > localstorage.getitem("dl-visited-date") //false currentdate < localstorage.getitem("dl-visited-date") //false 

localstorage.getitem return string (your date object implicitly stringified when stored in localstorage). if compare date object, both casted numbers, while works date object string become nan. , compares false anything.

you need parse before (using date constructor):

var date = new date(localstorage.getitem("dl-visited-date")),     currentdate = new date(); 

if want test them equality, need use plain numbers instead. use date.parse then:

var datestamp = date.parse(localstorage.getitem("dl-visited-date")),     currentdatestamp = date.now(); 

Comments

Popular posts from this blog

iphone - Three second countdown in cocos2d -

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -