Skip to content

Commit cad20ea

Browse files
authored
Update index.md
1 parent 9ba867e commit cad20ea

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

stdlib/Dates/docs/src/index.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,23 @@ julia> dt2 = Date("2015-01-02",df)
125125
2015-01-02
126126
```
127127

128-
You can also use the `dateformat""` string macro. This macro creates the `DateFormat` object once when the macro is expanded and uses the same `DateFormat` object even if a code snippet is run multiple times.
128+
Alternatively, use broadcasting:
129129

130130
```jldoctest
131-
julia> years = string.(2000:10000);
131+
julia> years = ["2015", "2016"];
132+
133+
julia> Date.(years, DateFormat("yyyy"))
134+
2-element Vector{Date}:
135+
2015-01-01
136+
2016-01-01
137+
```
132138

133-
julia> dates = Date.(years, dateformat"yyyy");
139+
You can also use the `dateformat""` string macro. This macro creates the `DateFormat` object once when the macro is expanded and uses the same `DateFormat` object even if a code snippet is run multiple times.
134140

135-
julia> dates[1:3]
136-
3-element Vector{Date}:
137-
2000-01-01
138-
2001-01-01
139-
2002-01-01
141+
```jldoctest
142+
julia> for i = 1:10^5
143+
Date("2015-01-01", dateformat"y-m-d")
144+
end
140145
```
141146

142147
As well as via the constructors, a `Date` or `DateTime` can be constructed from

0 commit comments

Comments
 (0)