Javascript date is invalid on iOS

前端 未结 7 825
忘掉有多难
忘掉有多难 2020-11-30 03:11

I\'m working on a Phonegap-based iOS app, which is already done for Android. The following lines are working fine for Android but not for iOS. Why?

var d = n         


        
7条回答
  •  既然无缘
    2020-11-30 03:24

    I can't tell you why. Maybe because iOS doesn't support the Javascript Date function as well as Android, or support a different format?

    But I can give you a workaround:

    var s = "2015-12-31 00:00:00".split(" ")[0].split("-"),
        d = new Date( s[0], s[1], s[2], 0, 0, 0 );
    
    console.log(d);
    

    var s = "2015-12-31 00:00:00".replace(/[ :]/g, "-").split("-"),
        d = new Date( s[0], s[1], s[2], s[3], s[4], s[5] );
    
    console.log(d);
    

提交回复
热议问题