sWhy is iPhone IOS showing invalid date for momentjs

前端 未结 3 1294
独厮守ぢ
独厮守ぢ 2021-01-28 19:59

I have a datepicker which was returning a moment object that was always in UTC timezone. I needed to do some logic on this date, but always wanted it in the users local timezone

相关标签:
3条回答
  • 2021-01-28 20:17

    follow this format. year should be at the beginning. have to use "/" instead of "-". cannot use "MMM" for month

    YYYY/MM/DD hh:mm A
    
    0 讨论(0)
  • 2021-01-28 20:21

    Try wrapping up with String function

    //strip submission date of timezone offset
    let submission_date = moment(String(this.state.startDate),'YYYY-MM-DD hh:mm:ss a');
    let last_date = moment(String(this.last_date),'YYYY-MM-DD hh:mm:ss a').diff(submission_date, 'days');
    

    Safari engine has some unique way of processing/parsing the date object

    0 讨论(0)
  • 2021-01-28 20:24

    I had figured out that it's the 'a' flag in the format string. I changed it to 'YYYY-MM-DDTHH:mm:ss' and it worked perfectly. Safari must not like am/pm data

    0 讨论(0)
提交回复
热议问题