官术网_书友最值得收藏!

Dates and times

To get the basic time information, you can use the time() function that returns, for example, 1.408719961424e9, which is the number of seconds since a predefined date called the epoch (normally, the 1st of January 1970 on a Unix system). This is useful for measuring the time interval between two events, for example, to benchmark how long a long calculation takes:

start_time = time() 
# long computation 
time_elapsed = time() - start_time 
println("Time elapsed: $time_elapsed") 

Use the Dates module that is built in into the standard library, with Date for days and DateTime for times down to milliseconds, to implement this. Additional time zone functionality can be added through the Timezones.jl package.

The Date and DateTime functions can be constructed as follows, or with simpler versions with less information:

  • d = Date(2014,9,1) returns 2014-09-01
  • dt = DateTime(2014,9,1,12,30,59,1) returns 2014-09-01T12:30:59.001

These objects can be compared and subtracted to get the duration. The Date function parts or fields can be retrieved through accessor functions, such as year(d), month(d), week(d), and day(d). Other useful functions exist, such as dayofweek, dayname, daysinmonth, dayofyear, isleapyear, and so on.

主站蜘蛛池模板: 海口市| 达拉特旗| 黄陵县| 彩票| 德阳市| 朝阳市| 峨眉山市| 嵊州市| 韩城市| 溧阳市| 平昌县| 喜德县| 大石桥市| 阳信县| 合山市| 新河县| 甘南县| 宜兴市| 闻喜县| 汤原县| 济宁市| 连州市| 津市市| 凌云县| 新干县| 临武县| 施秉县| 缙云县| 泗洪县| 南汇区| SHOW| 都江堰市| 应城市| 临澧县| 寿阳县| 南溪县| 海丰县| 逊克县| 仲巴县| 栖霞市| 吉木萨尔县|