将日期时间格式化为周数

3
我正在尝试使用 Dates.format() 函数将 DateTime 对象格式化为一个 String。我想要获取特定时间的周数,但是在文档中找不到正确的格式选项
我知道可以通过运行 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中,我可以使用“%V”来获取格式化的周。在Julia中是否有类似的方法?
1个回答

3

不,没有类似于%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

在这些说明符的代码中,有一条注释,指出应该有一种方法让包添加更多内容。

谢谢您的分享,非常有用!但我希望它还包含其他类似的日期函数。 - niczky12

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接