将 DateTime 格式化为周数

Formatting DateTime to week number

我正在尝试使用 Dates.format() 函数将 DateTime 对象格式化为 String。 我想获取特定时间的周数,但找不到正确的 formatting option in the docs.

我知道我可以通过 运行 Dates.week 得到这个,但我真的很想知道是否可以通过 format 获得更清晰的代码(并破解代码高尔夫挑战。 ..).

下面是一些实际代码:

julia> my_time = now()
2018-03-22T08:16:15.601

julia> Dates.week(my_time)
12

julia> Dates.format(my_time, "Y m d H:M:S")
"2018 3 22 8:16:15"

在 R 中,我可以对 get the weeks formatted 执行“%V”。 Julia 有类似的方法吗?

不,没有像 %V 这样的格式说明符:

julia> Base.Dates.CONVERSION_SPECIFIERS
Dict{Char,Type} with 12 entries:
  'm' => Base.Dates.Month
  'd' => Base.Dates.Day
  'M' => Base.Dates.Minute
  'Y' => Base.Dates.Year
  'e' => Base.Dates.DayOfWeekToken
  's' => Base.Dates.Millisecond
  'U' => Base.Dates.Month
  'E' => Base.Dates.DayOfWeekToken
  'H' => Base.Dates.Hour
  'y' => Base.Dates.Year
  'u' => Base.Dates.Month
  'S' => Base.Dates.Second

在这些说明符的代码中 a note 应该有一种方法可以让包添加更多。