teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

d

2019/09/04 09:54

投稿

tiitoi
tiitoi

スコア21960

answer CHANGED
@@ -13,6 +13,13 @@
13
13
  print(dt) # 2019-09-04 09:32:45.599578
14
14
  ```
15
15
 
16
+ 6桁であれば、[ISO 8601](https://ja.wikipedia.org/wiki/ISO_8601) フォーマットなので、Python 3.7 以降であれば、以下の関数を使っても datetime 型に変換できます。
17
+
18
+ ```python
19
+ dt = datetime.fromisoformat(s[:-1])
20
+ print(dt)
21
+ ```
22
+
16
23
  ## 参考文献
17
24
 
18
25
  * [python - How to convert a timestamp string with 7 digits on the microseconds part using strptime? - Stack Overflow](https://stackoverflow.com/questions/50500512/how-to-convert-a-timestamp-string-with-7-digits-on-the-microseconds-part-using-s)