Using moment.js to convert date to string “MM/dd/yyyy”

后端 未结 6 1652
有刺的猬
有刺的猬 2021-01-31 06:55

I need to take the date value from jquery datepicker turn it into string format \"MM/dd/yyyy\" so it can do the right ajax post. When the page loads or upon changing the datepic

相关标签:
6条回答
  • 2021-01-31 07:15

    I think you just have incorrect casing in the format string. According to the documentation this should work for you: MM/DD/YYYY

    moment.js documentation

    0 讨论(0)
  • 2021-01-31 07:22
    StartDate = moment(StartDate).format('MM-YYYY');
    

    ...and MySQL date format:

    StartDate = moment(StartDate).format('YYYY-MM-DD');
    
    0 讨论(0)
  • 2021-01-31 07:24

    Try this:

    var momentObj = $("#start_ts").datepicker("getDate");
    
    var yourDate = momentObj.format('L');
    
    0 讨论(0)
  • 2021-01-31 07:27

    this also might be relevant to anyone using React -

    install react-moment (npm i react-moment)

    import Moment from 'react-moment'
    
    
    <Moment format="MM/DD/YYYY">{yourTimeStamp}</Moment>
    

    (or any other format you'd like)

    0 讨论(0)
  • 2021-01-31 07:31

    Use:

    date.format("MM/DD/YYYY") or date.format("MM-DD-YYYY")}

    Other Supported formats for reference:

    Months:

    M 1 2 ... 11 12

    Mo 1st 2nd ... 11th 12th

    MM 01 02 ... 11 12

    MMM Jan Feb ... Nov Dec

    MMMM January February ... November December

    Day:

    d 0 1 ... 5 6

    do 0th 1st ... 5th 6th

    dd Su Mo ... Fr Sa

    ffffd Sun Mon ... Fri Sat

    ffffdd Sunday Monday ... Friday Saturday

    Year:

    YY 70 71 ... 29 30

    YYYY 1970 1971 ... 2029 2030

    Y 1970 1971 ... 9999 +10000 +10001

    0 讨论(0)
  • 2021-01-31 07:34
    .format('MM/DD/YYYY HH:mm:ss')
    
    0 讨论(0)
提交回复
热议问题