Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Date 有没有办法在Julia中定制日期格式?_Date_Parsing_Julia - Fatal编程技术网

Date 有没有办法在Julia中定制日期格式?

Date 有没有办法在Julia中定制日期格式?,date,parsing,julia,Date,Parsing,Julia,我想能够转换 "Tue Sep 01 00:00:26 +00:00 2020" 在Julia中使用内置日期函数转换为日期类型。 我只需要年、月和日期。这很棘手,因为这里有时区,因此需要使用时区。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",

我想能够转换

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

这很棘手,因为这里有时区,因此需要使用
时区。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

要分析日期,您需要dates.jl标准库。不过,要解析此特定格式,我认为您还需要TimeZones.jl包:

using Dates
using TimeZones # gives the `z` for the format below
fmt = dateformat"e u d H:M:S z y" # the format of your string
d = Date("Tue Sep 01 00:00:26 +00:00 2020", fmt)
然后,您可以简单地查看
d
的值,例如:

julia> d
2020-09-01

julia> year(d)
2020

julia> month(d)
9

julia> day(d)
1

哈你忍者把我打败了!:)是的,这是一场疯狂的比赛;-)