3

using this method

arrow.utcnow().format('YYYY_MM_DD_HH_mm_ss')

or something similar in arrow is it possible to get milliseconds added to the time ?

David Hancock
  • 1,063
  • 4
  • 16
  • 28

2 Answers2

4

In fact you can use up to 6 digits for representing fractions of a second:

>>> now = arrow.utcnow()
>>> now.format('YYYY-MM-DD HH:mm:ss.S')
u'2016-02-19 17:05:17.0'
>>> now.format('YYYY-MM-DD HH:mm:ss.SS')
u'2016-02-19 17:05:17.07'
>>> now.format('YYYY-MM-DD HH:mm:ss.SSS')
u'2016-02-19 17:05:17.073'
>>> now.format('YYYY-MM-DD HH:mm:ss.SSSS')
u'2016-02-19 17:05:17.0735'
>>> now.format('YYYY-MM-DD HH:mm:ss.SSSSS')
u'2016-02-19 17:05:17.07359'
>>> now.format('YYYY-MM-DD HH:mm:ss.SSSSSS')
u'2016-02-19 17:05:17.073591'

Starting from the 7th digit, the number start repeating (073591 in my case):

>>> now.format('YYYY-MM-DD HH:mm:ss.SSSSSS')
u'2016-02-19 17:05:17.073591'
>>> now.format('YYYY-MM-DD HH:mm:ss.SSSSSSSSSSSS')
u'2016-02-19 17:05:17.073591073591'
>>> now.format('YYYY-MM-DD HH:mm:ss.SSSSSSSSSSSSSSSSSS')
u'2016-02-19 17:05:17.073591073591073591'
P Daddy
  • 28,912
  • 9
  • 68
  • 92
César
  • 9,939
  • 6
  • 53
  • 74
3

You can use S, SS or SSS in your format string to get milliseconds. So: arrow.utcnow().format('YYYY_MM_DD_HH_mm_ss_SSS')

Aaron Christiansen
  • 11,584
  • 5
  • 52
  • 78