date - 有没有办法在 Julia 中制作自定义日期格式?

标签 date parsing julia

我希望能够转换

"Tue Sep 01 00:00:26 +00:00 2020"
使用内置的 Date 函数在 Julia 中转换为日期类型。
我只需要年、月和日。

最佳答案

这很棘手,因为您在这里有一个时区,因此您需要使用 TimeZones.jl

using TimeZones, Dates
df = Dates.DateFormat("e u d H:M:S z y");
d = ZonedDateTime("Tue Sep 01 00:00:26 +00:00 2020", df)
让我们看看我们得到了什么:
julia> d = ZonedDateTime("Tue Sep 01 00:00:26 +00:00 2020", df)
2020-09-01T00:00:26+00:00

julia> Date(d)
2020-09-01
更多尝试输入 ?DateFormat在控制台中 - 您将看到文档。
  Code     Matches   Comment
  –––––––– ––––––––– ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
  y        1996, 96  Returns year of 1996, 0096
  Y        1996, 96  Returns year of 1996, 0096. Equivalent to y
  m        1, 01     Matches 1 or 2-digit months
  u        Jan       Matches abbreviated months according to the locale keyword
  U        January   Matches full month names according to the locale keyword
  d        1, 01     Matches 1 or 2-digit days
  H        00        Matches hours (24-hour clock)
  I        00        For outputting hours with 12-hour clock
  M        00        Matches minutes
  S        00        Matches seconds
  s        .500      Matches milliseconds
  e        Mon, Tues Matches abbreviated days of the week
  E        Monday    Matches full name days of the week
  p        AM        Matches AM/PM (case-insensitive)
  yyyymmdd 19960101  Matches fixed-width year, month, and day

关于date - 有没有办法在 Julia 中制作自定义日期格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66700952/

相关文章:

javascript - 不确定这是 Chrome 浏览器上的错误

javascript - jquery,处理日期

css - 无点引擎解析器返回空字符串

java - Locale 的不同时间结果

c - 在c语言中将日期取为dd/mm/yy

java - 一种指定驱动任意对象解析和格式化的模式字符串的方法?

parsing - 在 StandardTokenParsers 中使用正则表达式

julia - 是否可以在 Julia 中将 Array{Num,1} 转换为 Array{Float64,1}?

grid - Julia 1.1 创建网格(网格中的点数组)

arrays - 如何在 julia 中启动带有列表元素的列表?