imanux's recent timeline updates
imanux

imanux

V2EX member #369630, joined on 2018-12-11 15:32:20 +08:00
imanux's recent replies
Apr 14, 2020
Replied to a topic by SlipStupig Python 如何将多种时间格式转化成统一格式呢
推荐使用 moment, 比 arrow 轻量一些.

```python

def date_identify():
mixed = [
'2019-10-24 09:20:44',
'2020-04-13',
'2019-11-04 13:11',
'04 月 13 日 10:41',
'2012 年 7 月 13 日',
]
for m in mixed[:3]:
print(moment.date(m).format('YYYYMMDD HH:mm:ss'))

ch1 = mixed[3]
print(moment.date(ch1, 'MM 月 DD 日 HH:mm').format('YYYYMMDD HH:mm:ss'))

ch1 = mixed[4]
print(moment.date(ch1, 'YYYY 年 M 月 DD 日').format('YYYYMMDD HH:mm:ss'))

```

当然如果还有更多的格式, 需要手动一个个匹配的.
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2598 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 14ms · UTC 16:01 · PVG 00:01 · LAX 09:01 · JFK 12:01
♥ Do have faith in what you're doing.