Convert String with month name to datetime

前端 未结 2 418
慢半拍i
慢半拍i 2020-11-29 05:55

I\'m using pickadate.js which returns the date in this format:

8 March, 2017

I would like to convert this to the dateti

2条回答
  •  情书的邮戳
    2020-11-29 06:12

    Mark Reed's advice might be best in your case. One frequently overlooked alternative for dates is the arrow module, which offers some interesting features. In this case you can do:

    >>> import arrow
    >>> arrow.get('8 March, 2017', 'D MMMM, YYYY').format('YYYY-MM-DD')
    '2017-03-08'
    

    As an example of a feature, if you capture that date you could format it in Russian.

    >>> aDate = arrow.get('8 March, 2017', 'D MMMM, YYYY')
    >>> aDate.format('YYYY MMMM DD', locale='ru')
    '2017 марта 08'
    

提交回复
热议问题