简体   繁体   中英

Timestamp milliseconds format in mysql and python

i have a simulator python which send the data to memsql, i'm trying to save timestamp in a column but it gives me an error

 Incorrect datetime value: '1530181024560' for column 'event_time' at row 

here is my code python i generate event_time like that format: 1530181024560

from datetime import datetime, timezone, timedelta

 now = datetime.now(timezone.utc)
 epoch = datetime(1970, 1, 1, tzinfo=timezone.utc) # use POSIX epoch
 posix_timestamp_micros = (now - epoch) // timedelta(microseconds=1)
 event_time = lambda:str(posix_timestamp_micros // 1000)

i tried datetime(3) and timestamp(3) but no way.

我应用的解决方案是将时间戳记保存为BigInt在数据库中,然后当我在spark中提取数据时(对我而言),我使用以下方法将值转换为时间戳记:evenTime.cast(TimestampType)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM