Date format: Difference between revisions
Content added Content deleted
m (→{{header|Diego}}: added Gregorian calendar in case thingy has defaulted to other calendar) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 9: | Line 9: | ||
=={{header|11l}}== |
=={{header|11l}}== |
||
< |
<syntaxhighlight lang="11l">print(Time().format(‘YYYY-MM-DD’)) |
||
print(Time().strftime(‘%A, %B %e, %Y’))</ |
print(Time().strftime(‘%A, %B %e, %Y’))</syntaxhighlight> |
||
=={{header|68000 Assembly}}== |
=={{header|68000 Assembly}}== |
||
Line 17: | Line 17: | ||
< |
<syntaxhighlight lang="68000devpac"> JSR SYS_READ_CALENDAR ;outputs calendar date to BIOS RAM |
||
MOVE.B #'2',D0 ;a character in single or double quotes refers to its ascii equivalent. |
MOVE.B #'2',D0 ;a character in single or double quotes refers to its ascii equivalent. |
||
Line 124: | Line 124: | ||
MOVE.B D1,D0 ;store in low word |
MOVE.B D1,D0 ;store in low word |
||
popWord D1 |
popWord D1 |
||
rts</ |
rts</syntaxhighlight> |
||
Output can be seen [https://ibb.co/52Ks0yf here,] but is also reproduced below: |
Output can be seen [https://ibb.co/52Ks0yf here,] but is also reproduced below: |
||
Line 133: | Line 133: | ||
=={{header|8th}}== |
=={{header|8th}}== |
||
< |
<syntaxhighlight lang="forth"> |
||
d:new |
d:new |
||
"%Y-%M-%D" over d:format . cr |
"%Y-%M-%D" over d:format . cr |
||
"%W, %N %D, %Y" over d:format . cr |
"%W, %N %D, %Y" over d:format . cr |
||
bye |
bye |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|AArch64 Assembly}}== |
=={{header|AArch64 Assembly}}== |
||
{{works with|as|Raspberry Pi 3B version Buster 64 bits}} |
{{works with|as|Raspberry Pi 3B version Buster 64 bits}} |
||
<syntaxhighlight lang="aarch64 assembly"> |
|||
<lang AArch64 Assembly> |
|||
/* ARM assembly AARCH64 Raspberry PI 3B */ |
/* ARM assembly AARCH64 Raspberry PI 3B */ |
||
/* program dateFormat64.s */ |
/* program dateFormat64.s */ |
||
Line 463: | Line 463: | ||
/* for this file see task include a file in language AArch64 assembly */ |
/* for this file see task include a file in language AArch64 assembly */ |
||
.include "../includeARM64.inc" |
.include "../includeARM64.inc" |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|ABAP}}== |
=={{header|ABAP}}== |
||
<syntaxhighlight lang="abap"> |
|||
<lang ABAP> |
|||
report zdate. |
report zdate. |
||
data: lv_month type string, |
data: lv_month type string, |
||
Line 487: | Line 487: | ||
concatenate sy-datum(4) '-' sy-datum+4(2) '-' sy-datum+6(2) into lv_date. |
concatenate sy-datum(4) '-' sy-datum+4(2) '-' sy-datum+6(2) into lv_date. |
||
write / lv_date. |
write / lv_date. |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Action!}}== |
=={{header|Action!}}== |
||
< |
<syntaxhighlight lang="action!">DEFINE PTR="CARD" |
||
TYPE Date=[ |
TYPE Date=[ |
||
Line 560: | Line 560: | ||
PrintDateShort(d) PutE() |
PrintDateShort(d) PutE() |
||
PrintDateLong(d) PutE() |
PrintDateLong(d) PutE() |
||
RETURN</ |
RETURN</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Date_format.png Screenshot from Atari 8-bit computer] |
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Date_format.png Screenshot from Atari 8-bit computer] |
||
Line 569: | Line 569: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
< |
<syntaxhighlight lang="ada">with Ada.Calendar; use Ada.Calendar; |
||
with Ada.Calendar.Formatting; use Ada.Calendar.Formatting; |
with Ada.Calendar.Formatting; use Ada.Calendar.Formatting; |
||
with Ada.Text_IO; use Ada.Text_IO; |
with Ada.Text_IO; use Ada.Text_IO; |
||
Line 612: | Line 612: | ||
& Year_Number'Image (Ada.Calendar.Year (Today)) |
& Year_Number'Image (Ada.Calendar.Year (Today)) |
||
); |
); |
||
end Date_Format;</ |
end Date_Format;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 625: | Line 625: | ||
Note: the '''format''' can be used for both printing ''and'' reading date data. |
Note: the '''format''' can be used for both printing ''and'' reading date data. |
||
< |
<syntaxhighlight lang="algol68"># define the layout of the date/time as provided by the call to local time # |
||
STRUCT ( INT sec, min, hour, mday, mon, year, wday, yday, isdst) tm = (6,5,4,3,2,1,7,~,8); |
STRUCT ( INT sec, min, hour, mday, mon, year, wday, yday, isdst) tm = (6,5,4,3,2,1,7,~,8); |
||
Line 647: | Line 647: | ||
printf((unix time repr, now[wday OF tm], now[mon OF tm], now[mday OF tm], |
printf((unix time repr, now[wday OF tm], now[mon OF tm], now[mday OF tm], |
||
now[hour OF tm:sec OF tm], now[isdst OF tm]+1, now[year OF tm], $l$))</ |
now[hour OF tm:sec OF tm], now[isdst OF tm]+1, now[year OF tm], $l$))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 656: | Line 656: | ||
=={{header|Apex}}== |
=={{header|Apex}}== |
||
< |
<syntaxhighlight lang="java"> |
||
Datetime dtNow = datetime.now(); |
Datetime dtNow = datetime.now(); |
||
String strDt1 = dtNow.format('yyyy-MM-dd'); |
String strDt1 = dtNow.format('yyyy-MM-dd'); |
||
Line 662: | Line 662: | ||
system.debug(strDt1); // "2007-11-10" |
system.debug(strDt1); // "2007-11-10" |
||
system.debug(strDt2); //"Sunday, November 10, 2007" |
system.debug(strDt2); //"Sunday, November 10, 2007" |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 677: | Line 677: | ||
Whether or not they happen to work, to insist on posting code containing things which have never been part of the language without noting them as hacks, when they're entirely unnecessary, and deleting legitimate and effective code to make way for them, is seriously to misinform readers. |
Whether or not they happen to work, to insist on posting code containing things which have never been part of the language without noting them as hacks, when they're entirely unnecessary, and deleting legitimate and effective code to make way for them, is seriously to misinform readers. |
||
< |
<syntaxhighlight lang="applescript">set {year:y, month:m, day:d, weekday:w} to (current date) |
||
tell (y * 10000 + m * 100 + d) as text to set shortFormat to text 1 thru 4 & "-" & text 5 thru 6 & "-" & text 7 thru 8 |
tell (y * 10000 + m * 100 + d) as text to set shortFormat to text 1 thru 4 & "-" & text 5 thru 6 & "-" & text 7 thru 8 |
||
set longFormat to (w as text) & (", " & m) & (space & d) & (", " & y) |
set longFormat to (w as text) & (", " & m) & (space & d) & (", " & y) |
||
return (shortFormat & linefeed & longFormat)</ |
return (shortFormat & linefeed & longFormat)</syntaxhighlight> |
||
{{output}} |
{{output}} |
||
< |
<syntaxhighlight lang="applescript">"2020-10-28 |
||
Wednesday, October 28, 2020"</ |
Wednesday, October 28, 2020"</syntaxhighlight> |
||
===Hack alternative=== |
===Hack alternative=== |
||
Line 702: | Line 702: | ||
< |
<syntaxhighlight lang="applescript">tell (the current date) |
||
set shortdate to text 1 thru 10 of (it as «class isot» as string) |
set shortdate to text 1 thru 10 of (it as «class isot» as string) |
||
set longdate to the contents of [its weekday, ", ", ¬ |
set longdate to the contents of [its weekday, ", ", ¬ |
||
Line 709: | Line 709: | ||
log the shortdate |
log the shortdate |
||
log the longdate</ |
log the longdate</syntaxhighlight> |
||
{{output}} |
{{output}} |
||
Line 718: | Line 718: | ||
Or, emphasising productivity and functional composition: |
Or, emphasising productivity and functional composition: |
||
< |
<syntaxhighlight lang="applescript">-- iso8601Short :: Date -> String |
||
on iso8601Short(dte) |
on iso8601Short(dte) |
||
text 1 thru 10 of iso8601Local(dte) |
text 1 thru 10 of iso8601Local(dte) |
||
Line 788: | Line 788: | ||
set my text item delimiters to dlm |
set my text item delimiters to dlm |
||
s |
s |
||
end unlines</ |
end unlines</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>2020-09-11 |
<pre>2020-09-11 |
||
Line 795: | Line 795: | ||
=={{header|ARM Assembly}}== |
=={{header|ARM Assembly}}== |
||
{{works with|as|Raspberry Pi}} |
{{works with|as|Raspberry Pi}} |
||
<syntaxhighlight lang="arm assembly"> |
|||
<lang ARM Assembly> |
|||
/* ARM assembly Raspberry PI */ |
/* ARM assembly Raspberry PI */ |
||
/* program dateFormat.s */ |
/* program dateFormat.s */ |
||
Line 1,143: | Line 1,143: | ||
/***************************************************/ |
/***************************************************/ |
||
.include "../affichage.inc" |
.include "../affichage.inc" |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{Output}} |
{{Output}} |
||
<pre> |
<pre> |
||
Line 1,158: | Line 1,158: | ||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
< |
<syntaxhighlight lang="rebol">currentTime: now |
||
print to :string.format: "YYYY-MM-dd" currentTime |
print to :string.format: "YYYY-MM-dd" currentTime |
||
print to :string.format: "dddd, MMMM dd, YYYY" currentTime</ |
print to :string.format: "dddd, MMMM dd, YYYY" currentTime</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,169: | Line 1,169: | ||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
< |
<syntaxhighlight lang="autohotkey">FormatTime, Date1, , yyyy-MM-dd ; "2007-11-10" |
||
FormatTime, Date2, , LongDate ; "Sunday, November 10, 2007" |
FormatTime, Date2, , LongDate ; "Sunday, November 10, 2007" |
||
MsgBox %Date1% `n %Date2%</ |
MsgBox %Date1% `n %Date2%</syntaxhighlight> |
||
=={{header|AutoIt}}== |
=={{header|AutoIt}}== |
||
This solution uses the locale settings for names of days and months. |
This solution uses the locale settings for names of days and months. |
||
<syntaxhighlight lang="autoit"> |
|||
<lang AutoIt> |
|||
#include <Date.au3> |
#include <Date.au3> |
||
Line 1,207: | Line 1,207: | ||
Return $ret[3] |
Return $ret[3] |
||
EndFunc |
EndFunc |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,217: | Line 1,217: | ||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
{{works with|Gawk}} |
{{works with|Gawk}} |
||
< |
<syntaxhighlight lang="awk">$ awk 'BEGIN{t=systime();print strftime("%Y-%m-%d",t)"\n"strftime("%A, %B %d, %Y",t)}' |
||
2009-05-15 |
2009-05-15 |
||
Friday, May 15, 2009</ |
Friday, May 15, 2009</syntaxhighlight> |
||
=={{header|BaCon}}== |
=={{header|BaCon}}== |
||
< |
<syntaxhighlight lang="freebasic">' Date format |
||
n = NOW |
n = NOW |
||
PRINT YEAR(n), MONTH(n), DAY(n) FORMAT "%ld-%02ld-%02ld\n" |
PRINT YEAR(n), MONTH(n), DAY(n) FORMAT "%ld-%02ld-%02ld\n" |
||
PRINT WEEKDAY$(n), MONTH$(n), DAY(n), YEAR(n) FORMAT "%s, %s %02ld, %ld\n"</ |
PRINT WEEKDAY$(n), MONTH$(n), DAY(n), YEAR(n) FORMAT "%s, %s %02ld, %ld\n"</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,234: | Line 1,234: | ||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
{{works with|FreeBASIC}} |
{{works with|FreeBASIC}} |
||
< |
<syntaxhighlight lang="freebasic">#include "vbcompat.bi" |
||
DIM today As Double = Now() |
DIM today As Double = Now() |
||
PRINT Format(today, "yyyy-mm-dd") |
PRINT Format(today, "yyyy-mm-dd") |
||
PRINT Format(today, "dddd, mmmm d, yyyy")</ |
PRINT Format(today, "dddd, mmmm d, yyyy")</syntaxhighlight> |
||
=={{header|Batch File}}== |
=={{header|Batch File}}== |
||
< |
<syntaxhighlight lang="dos"> |
||
@echo off |
@echo off |
||
setlocal enabledelayedexpansion |
setlocal enabledelayedexpansion |
||
Line 1,278: | Line 1,278: | ||
echo %fulldayname%, %monthname% %day%, %year% |
echo %fulldayname%, %monthname% %day%, %year% |
||
pause>nul |
pause>nul |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,286: | Line 1,286: | ||
=={{header|BBC BASIC}}== |
=={{header|BBC BASIC}}== |
||
< |
<syntaxhighlight lang="bbcbasic"> daysow$ = "Sunday Monday Tuesday Wednesday Thursday Friday Saturday" |
||
months$ = "January February March April May June " + \ |
months$ = "January February March April May June " + \ |
||
\ "July August September October November December" |
\ "July August September October November December" |
||
Line 1,303: | Line 1,303: | ||
DEF FNrtrim(A$) |
DEF FNrtrim(A$) |
||
WHILE RIGHT$(A$) = " " A$ = LEFT$(A$) : ENDWHILE |
WHILE RIGHT$(A$) = " " A$ = LEFT$(A$) : ENDWHILE |
||
= A$</ |
= A$</syntaxhighlight> |
||
=={{header|Beads}}== |
=={{header|Beads}}== |
||
Line 1,333: | Line 1,333: | ||
// [iso time] = [hour]:[minute]:[second], e.g. 18:06:05 |
// [iso time] = [hour]:[minute]:[second], e.g. 18:06:05 |
||
</pre> |
</pre> |
||
< |
<syntaxhighlight lang="beads">beads 1 program 'Date format' |
||
calc main_init |
calc main_init |
||
log time_to_str('[iso date]') |
log time_to_str('[iso date]') |
||
log time_to_str('[sunday], [january] [day2], [year]')</ |
log time_to_str('[sunday], [january] [day2], [year]')</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,346: | Line 1,346: | ||
=={{header|C}}== |
=={{header|C}}== |
||
< |
<syntaxhighlight lang="c">#include <stdlib.h> |
||
#include <stdio.h> |
#include <stdio.h> |
||
#include <time.h> |
#include <time.h> |
||
Line 1,368: | Line 1,368: | ||
(void) printf("%s\n", buf); |
(void) printf("%s\n", buf); |
||
return EXIT_SUCCESS; |
return EXIT_SUCCESS; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,376: | Line 1,376: | ||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
< |
<syntaxhighlight lang="csharp">using System; |
||
namespace RosettaCode.DateFormat |
namespace RosettaCode.DateFormat |
||
Line 1,389: | Line 1,389: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|C++}}== |
=={{header|C++}}== |
||
< |
<syntaxhighlight lang="cpp">// Display the current date in the formats of "2007-11-10" |
||
// and "Sunday, November 10, 2007". |
// and "Sunday, November 10, 2007". |
||
Line 1,455: | Line 1,455: | ||
std::cout << d.getTextDate() << std::endl; |
std::cout << d.getTextDate() << std::endl; |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,463: | Line 1,463: | ||
=={{header|Clojure}}== |
=={{header|Clojure}}== |
||
< |
<syntaxhighlight lang="lisp">(let [now (.getTime (java.util.Calendar/getInstance)) |
||
f1 (java.text.SimpleDateFormat. "yyyy-MM-dd") |
f1 (java.text.SimpleDateFormat. "yyyy-MM-dd") |
||
f2 (java.text.SimpleDateFormat. "EEEE, MMMM dd, yyyy")] |
f2 (java.text.SimpleDateFormat. "EEEE, MMMM dd, yyyy")] |
||
(println (.format f1 now)) |
(println (.format f1 now)) |
||
(println (.format f2 now)))</ |
(println (.format f2 now)))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,475: | Line 1,475: | ||
=={{header|COBOL}}== |
=={{header|COBOL}}== |
||
{{works with|OpenCOBOL}} |
{{works with|OpenCOBOL}} |
||
< |
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION. |
||
PROGRAM-ID. Date-Format. |
PROGRAM-ID. Date-Format. |
||
Line 1,538: | Line 1,538: | ||
GOBACK |
GOBACK |
||
.</ |
.</syntaxhighlight> |
||
=={{header|CoffeeScript}}== |
=={{header|CoffeeScript}}== |
||
=== ECMAScript ≥ 5.1 === |
=== ECMAScript ≥ 5.1 === |
||
Is supported by at least: Chrome 24, Firefox/Gecko 29, IE 11, Opera 15, and Node.js (at least as of 2015). |
Is supported by at least: Chrome 24, Firefox/Gecko 29, IE 11, Opera 15, and Node.js (at least as of 2015). |
||
< |
<syntaxhighlight lang="coffeescript"> |
||
date = new Date |
date = new Date |
||
Line 1,557: | Line 1,557: | ||
day: 'numeric' |
day: 'numeric' |
||
year: 'numeric' |
year: 'numeric' |
||
</syntaxhighlight> |
|||
</lang> |
|||
=== Portable version === |
=== Portable version === |
||
< |
<syntaxhighlight lang="coffeescript"> |
||
# JS does not have extensive formatting support out of the box. This code shows |
# JS does not have extensive formatting support out of the box. This code shows |
||
# how you could create a date formatter object. |
# how you could create a date formatter object. |
||
Line 1,587: | Line 1,587: | ||
console.log formatter.brief(date) |
console.log formatter.brief(date) |
||
console.log formatter.verbose(date) |
console.log formatter.verbose(date) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,596: | Line 1,596: | ||
=={{header|ColdFusion}}== |
=={{header|ColdFusion}}== |
||
< |
<syntaxhighlight lang="cfm"><cfoutput> |
||
#dateFormat(Now(), "YYYY-MM-DD")#<br /> |
#dateFormat(Now(), "YYYY-MM-DD")#<br /> |
||
#dateFormat(Now(), "DDDD, MMMM DD, YYYY")# |
#dateFormat(Now(), "DDDD, MMMM DD, YYYY")# |
||
</cfoutput></ |
</cfoutput></syntaxhighlight> |
||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |
||
< |
<syntaxhighlight lang="lisp">(defconstant *day-names* |
||
#("Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday")) |
#("Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday")) |
||
(defconstant *month-names* |
(defconstant *month-names* |
||
Line 1,611: | Line 1,611: | ||
(format t "~4d-~2,'0d-~2,'0d~%" year month date) |
(format t "~4d-~2,'0d-~2,'0d~%" year month date) |
||
(format t "~a, ~a ~d, ~4d~%" |
(format t "~a, ~a ~d, ~4d~%" |
||
(aref *day-names* day) (aref *month-names* month) date year))</ |
(aref *day-names* day) (aref *month-names* month) date year))</syntaxhighlight> |
||
With the local-time library: |
With the local-time library: |
||
< |
<syntaxhighlight lang="lisp"> |
||
(local-time:format-timestring nil (local-time:now) :format '(:year "-" (:month 2) "-" (:day 2))) |
(local-time:format-timestring nil (local-time:now) :format '(:year "-" (:month 2) "-" (:day 2))) |
||
;; => "2019-11-13" |
;; => "2019-11-13" |
||
(local-time:format-timestring nil (local-time:now) :format '(:long-weekday ", " :long-month #\space (:day 2) ", " :year)) |
(local-time:format-timestring nil (local-time:now) :format '(:long-weekday ", " :long-month #\space (:day 2) ", " :year)) |
||
;; => "Wednesday, November 13, 2019" |
;; => "Wednesday, November 13, 2019" |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Component Pascal}}== |
=={{header|Component Pascal}}== |
||
BlackBox Component Builder |
BlackBox Component Builder |
||
< |
<syntaxhighlight lang="oberon2"> |
||
MODULE DateFormat; |
MODULE DateFormat; |
||
IMPORT StdLog, Dates; |
IMPORT StdLog, Dates; |
||
Line 1,646: | Line 1,646: | ||
END Do; |
END Do; |
||
END DateFormat. |
END DateFormat. |
||
</syntaxhighlight> |
|||
</lang> |
|||
Execute: ^Q DateFormat.Do<br/> |
Execute: ^Q DateFormat.Do<br/> |
||
{{out}} |
{{out}} |
||
Line 1,660: | Line 1,660: | ||
=={{header|Crystal}}== |
=={{header|Crystal}}== |
||
{{works with|Crystal|0.33}} |
{{works with|Crystal|0.33}} |
||
< |
<syntaxhighlight lang="crystal">require "time" |
||
time = Time.local |
time = Time.local |
||
puts time.to_s("%Y-%m-%d") |
puts time.to_s("%Y-%m-%d") |
||
puts time.to_s("%A, %B %d, %Y") |
puts time.to_s("%A, %B %d, %Y") |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|D}}== |
=={{header|D}}== |
||
{{works with|D|DMD 1.026}} |
{{works with|D|DMD 1.026}} |
||
{{libheader|Tango}} |
{{libheader|Tango}} |
||
< |
<syntaxhighlight lang="d">module datetimedemo ; |
||
import tango.time.Time ; |
import tango.time.Time ; |
||
Line 1,686: | Line 1,686: | ||
d = g.toTime(2008, 2, 1, 0, 0, 0, 0, g.AD_ERA) ; |
d = g.toTime(2008, 2, 1, 0, 0, 0, 0, g.AD_ERA) ; |
||
Stdout.format("{:dddd, MMMM d, yyy}", d).newline ; |
Stdout.format("{:dddd, MMMM d, yyy}", d).newline ; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>2007-11-10 |
<pre>2007-11-10 |
||
Line 1,693: | Line 1,693: | ||
=={{header|Delphi}}== |
=={{header|Delphi}}== |
||
< |
<syntaxhighlight lang="delphi">ShowMessage(FormatDateTime('yyyy-mm-dd', Now) +#13#10+ FormatDateTime('dddd, mmmm dd, yyyy', Now));</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,702: | Line 1,702: | ||
=={{header|Diego}}== |
=={{header|Diego}}== |
||
< |
<syntaxhighlight lang="diego">me_lang(en)_cal(gregorian); |
||
me_msg()_now()_format(yyyy-mm-dd); |
me_msg()_now()_format(yyyy-mm-dd); |
||
me_msg()_now()_format(eeee, mmmm dd, yyyy);</ |
me_msg()_now()_format(eeee, mmmm dd, yyyy);</syntaxhighlight> |
||
=={{header|EGL}}== |
=={{header|EGL}}== |
||
<syntaxhighlight lang="egl"> |
|||
<lang EGL> |
|||
// 2012-09-26 |
// 2012-09-26 |
||
SysLib.writeStdout(StrLib.formatDate(DateTimeLib.currentDate(), "yyyy-MM-dd")); |
SysLib.writeStdout(StrLib.formatDate(DateTimeLib.currentDate(), "yyyy-MM-dd")); |
||
Line 1,713: | Line 1,713: | ||
SysLib.setLocale("en", "US"); |
SysLib.setLocale("en", "US"); |
||
SysLib.writeStdout(StrLib.formatDate(DateTimeLib.currentDate(), "EEEE, MMMM dd, yyyy")); |
SysLib.writeStdout(StrLib.formatDate(DateTimeLib.currentDate(), "EEEE, MMMM dd, yyyy")); |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,723: | Line 1,723: | ||
{{trans|Erlang}} |
{{trans|Erlang}} |
||
{{works with|Elixir|1.4}} |
{{works with|Elixir|1.4}} |
||
< |
<syntaxhighlight lang="elixir">defmodule Date_format do |
||
def iso_date, do: Date.utc_today |> Date.to_iso8601 |
def iso_date, do: Date.utc_today |> Date.to_iso8601 |
||
Line 1,745: | Line 1,745: | ||
IO.puts Date_format.long_date |
IO.puts Date_format.long_date |
||
IO.puts Date_format.iso_date(2007,11,10) |
IO.puts Date_format.iso_date(2007,11,10) |
||
IO.puts Date_format.long_date(2007,11,10)</ |
IO.puts Date_format.long_date(2007,11,10)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,756: | Line 1,756: | ||
=={{header|Emacs Lisp}}== |
=={{header|Emacs Lisp}}== |
||
< |
<syntaxhighlight lang="lisp">(format-time-string "%Y-%m-%d") |
||
(format-time-string "%F") ;; new in Emacs 24 |
(format-time-string "%F") ;; new in Emacs 24 |
||
;; => "2015-11-08" |
;; => "2015-11-08" |
||
(format-time-string "%A, %B %e, %Y") |
(format-time-string "%A, %B %e, %Y") |
||
;; => "Sunday, November 8, 2015"</ |
;; => "Sunday, November 8, 2015"</syntaxhighlight> |
||
<code>%e</code> is blank-padded day number, or <code>%d</code> for zero-padded. Month and weekday names follow the current locale. On a POSIX style system this is the usual <code>LC_TIME</code> or <code>LC_ALL</code> environment variables. GNU Emacs variable <code>system-time-locale</code> can override this if desired. |
<code>%e</code> is blank-padded day number, or <code>%d</code> for zero-padded. Month and weekday names follow the current locale. On a POSIX style system this is the usual <code>LC_TIME</code> or <code>LC_ALL</code> environment variables. GNU Emacs variable <code>system-time-locale</code> can override this if desired. |
||
Line 1,767: | Line 1,767: | ||
=={{header|Erlang}}== |
=={{header|Erlang}}== |
||
< |
<syntaxhighlight lang="erlang">-module(format_date). |
||
-export([iso_date/0, iso_date/1, iso_date/3, long_date/0, long_date/1, long_date/3]). |
-export([iso_date/0, iso_date/1, iso_date/3, long_date/0, long_date/1, long_date/3]). |
||
-import(calendar,[day_of_the_week/1]). |
-import(calendar,[day_of_the_week/1]). |
||
Line 1,790: | Line 1,790: | ||
MonthName = element(Month, Months), |
MonthName = element(Month, Months), |
||
append([WeekdayName, ", ", MonthName, " ", integer_to_list(Day), ", ", |
append([WeekdayName, ", ", MonthName, " ", integer_to_list(Day), ", ", |
||
integer_to_list(Year)]).</ |
integer_to_list(Year)]).</syntaxhighlight> |
||
=={{header|Euphoria}}== |
=={{header|Euphoria}}== |
||
< |
<syntaxhighlight lang="euphoria">constant days = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"} |
||
constant months = {"January","February","March","April","May","June", |
constant months = {"January","February","March","April","May","June", |
||
"July","August","September","October","November","December"} |
"July","August","September","October","November","December"} |
||
Line 1,803: | Line 1,803: | ||
printf(1,"%d-%02d-%02d\n",now[1..3]) |
printf(1,"%d-%02d-%02d\n",now[1..3]) |
||
printf(1,"%s, %s %d, %d\n",{days[now[7]],months[now[2]],now[3],now[1]})</ |
printf(1,"%s, %s %d, %d\n",{days[now[7]],months[now[2]],now[3],now[1]})</syntaxhighlight> |
||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
"F# Interactive" session: |
"F# Interactive" session: |
||
< |
<syntaxhighlight lang="fsharp">> open System;; |
||
> Console.WriteLine( DateTime.Now.ToString("yyyy-MM-dd") );; |
> Console.WriteLine( DateTime.Now.ToString("yyyy-MM-dd") );; |
||
2010-08-13 |
2010-08-13 |
||
> Console.WriteLine( "{0:D}", DateTime.Now );; |
> Console.WriteLine( "{0:D}", DateTime.Now );; |
||
Friday, August 13, 2010</ |
Friday, August 13, 2010</syntaxhighlight> |
||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
< |
<syntaxhighlight lang="factor">USING: formatting calendar io ; |
||
now "%Y-%m-%d" strftime print |
now "%Y-%m-%d" strftime print |
||
now "%A, %B %d, %Y" strftime print</ |
now "%A, %B %d, %Y" strftime print</syntaxhighlight> |
||
=={{header|Fantom}}== |
=={{header|Fantom}}== |
||
Line 1,823: | Line 1,823: | ||
Today's date can be retrieved using 'Date.today'. The 'toLocale' method can be passed formatting information to determine how the date should be represented as a string. The rules are described at http://fantom.org/doc/sys/Date.html#toLocale |
Today's date can be retrieved using 'Date.today'. The 'toLocale' method can be passed formatting information to determine how the date should be represented as a string. The rules are described at http://fantom.org/doc/sys/Date.html#toLocale |
||
< |
<syntaxhighlight lang="fantom"> |
||
fansh> Date.today.toLocale("YYYY-MM-DD") |
fansh> Date.today.toLocale("YYYY-MM-DD") |
||
2011-02-24 |
2011-02-24 |
||
fansh> Date.today.toLocale("WWWW, MMMM DD, YYYY") |
fansh> Date.today.toLocale("WWWW, MMMM DD, YYYY") |
||
Thursday, February 24, 2011 |
Thursday, February 24, 2011 |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
< |
<syntaxhighlight lang="forth">: .-0 ( n -- n ) |
||
[char] - emit |
[char] - emit |
||
dup 10 < if [char] 0 emit then ; |
dup 10 < if [char] 0 emit then ; |
||
Line 1,885: | Line 1,885: | ||
3dup weekday weekdays type ." , " |
3dup weekday weekdays type ." , " |
||
>R 1- months type space 1 u.r ." , " R> . |
>R 1- months type space 1 u.r ." , " R> . |
||
drop drop drop ;</ |
drop drop drop ;</syntaxhighlight> |
||
=== Version 2: Meta Language === |
=== Version 2: Meta Language === |
||
Line 1,962: | Line 1,962: | ||
{{works with|Fortran|95 and later}} |
{{works with|Fortran|95 and later}} |
||
The subroutine DATE_AND_TIME does not return day of week information so we have to write our own function for that |
The subroutine DATE_AND_TIME does not return day of week information so we have to write our own function for that |
||
< |
<syntaxhighlight lang="fortran">PROGRAM DATE |
||
IMPLICIT NONE |
IMPLICIT NONE |
||
Line 2,030: | Line 2,030: | ||
END FUNCTION Day_of_week |
END FUNCTION Day_of_week |
||
END PROGRAM DATE</ |
END PROGRAM DATE</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
2008-12-14 |
2008-12-14 |
||
Line 2,036: | Line 2,036: | ||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
< |
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64 |
||
#Include "vbcompat.bi" |
#Include "vbcompat.bi" |
||
Line 2,045: | Line 2,045: | ||
Print |
Print |
||
Print "Press any key to quit the program" |
Print "Press any key to quit the program" |
||
Sleep</ |
Sleep</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,054: | Line 2,054: | ||
=={{header|Free Pascal}}== |
=={{header|Free Pascal}}== |
||
< |
<syntaxhighlight lang="pascal">program Format_Date_Time; |
||
uses |
uses |
||
SysUtils; |
SysUtils; |
||
Line 2,060: | Line 2,060: | ||
WriteLn(FormatDateTime('yyyy-mm-dd', Now) +#13#10+ FormatDateTime('dddd, mmmm dd, yyyy', Now)); |
WriteLn(FormatDateTime('yyyy-mm-dd', Now) +#13#10+ FormatDateTime('dddd, mmmm dd, yyyy', Now)); |
||
end. |
end. |
||
</ |
</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 2,068: | Line 2,068: | ||
=={{header|Frink}}== |
=={{header|Frink}}== |
||
< |
<syntaxhighlight lang="frink"> |
||
println[now[] -> ### yyyy-MM-dd ###] |
println[now[] -> ### yyyy-MM-dd ###] |
||
println[now[] -> ### EEEE, MMMM d, yyyy ###] |
println[now[] -> ### EEEE, MMMM d, yyyy ###] |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|FunL}}== |
=={{header|FunL}}== |
||
< |
<syntaxhighlight lang="funl">println( format('%tF', $date) ) |
||
println( format('%1$tA, %1$tB %1$td, %1$tY', $date) )</ |
println( format('%1$tA, %1$tB %1$td, %1$tY', $date) )</syntaxhighlight> |
||
=={{header|FutureBasic}}== |
=={{header|FutureBasic}}== |
||
< |
<syntaxhighlight lang="futurebasic">window 1 |
||
print date(@"yyyy-MM-dd") |
print date(@"yyyy-MM-dd") |
||
print date(@"EEEE, MMMM dd, yyyy") |
print date(@"EEEE, MMMM dd, yyyy") |
||
HandleEvents</ |
HandleEvents</syntaxhighlight> |
||
=={{header|Gambas}}== |
=={{header|Gambas}}== |
||
'''[https://gambas-playground.proko.eu/ You can run this code. Copy the code, click this link, paste it in and press 'Run !']''' |
'''[https://gambas-playground.proko.eu/ You can run this code. Copy the code, click this link, paste it in and press 'Run !']''' |
||
< |
<syntaxhighlight lang="gambas">Public Sub Main() |
||
Print Format(Now, "yyyy - mm - dd") |
Print Format(Now, "yyyy - mm - dd") |
||
Print Format(Now, "dddd, mmmm dd, yyyy") |
Print Format(Now, "dddd, mmmm dd, yyyy") |
||
End</ |
End</syntaxhighlight> |
||
Output: |
Output: |
||
<pre> |
<pre> |
||
Line 2,101: | Line 2,101: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
In an interesting design, you specify your format by providing the format for the date and time 01/02 03:04:05PM '06 -0700 |
In an interesting design, you specify your format by providing the format for the date and time 01/02 03:04:05PM '06 -0700 |
||
< |
<syntaxhighlight lang="go">package main |
||
import "time" |
import "time" |
||
Line 2,109: | Line 2,109: | ||
fmt.Println(time.Now().Format("2006-01-02")) |
fmt.Println(time.Now().Format("2006-01-02")) |
||
fmt.Println(time.Now().Format("Monday, January 2, 2006")) |
fmt.Println(time.Now().Format("Monday, January 2, 2006")) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 2,118: | Line 2,118: | ||
=={{header|Groovy}}== |
=={{header|Groovy}}== |
||
Solution: |
Solution: |
||
< |
<syntaxhighlight lang="groovy">def isoFormat = { date -> date.format("yyyy-MM-dd") } |
||
def longFormat = { date -> date.format("EEEE, MMMM dd, yyyy") }</ |
def longFormat = { date -> date.format("EEEE, MMMM dd, yyyy") }</syntaxhighlight> |
||
Test Program: |
Test Program: |
||
< |
<syntaxhighlight lang="groovy">def now = new Date() |
||
println isoFormat(now) |
println isoFormat(now) |
||
println longFormat(now)</ |
println longFormat(now)</syntaxhighlight> |
||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
< |
<syntaxhighlight lang="haskell">import Data.Time |
||
(FormatTime, formatTime, defaultTimeLocale, utcToLocalTime, |
(FormatTime, formatTime, defaultTimeLocale, utcToLocalTime, |
||
getCurrentTimeZone, getCurrentTime) |
getCurrentTimeZone, getCurrentTime) |
||
Line 2,137: | Line 2,137: | ||
main = do |
main = do |
||
t <- pure utcToLocalTime <*> getCurrentTimeZone <*> getCurrentTime |
t <- pure utcToLocalTime <*> getCurrentTimeZone <*> getCurrentTime |
||
putStrLn $ unlines (formats <*> pure t)</ |
putStrLn $ unlines (formats <*> pure t)</syntaxhighlight> |
||
'''Sample output:''' |
'''Sample output:''' |
||
<pre>2017-06-05 |
<pre>2017-06-05 |
||
Line 2,143: | Line 2,143: | ||
=={{header|HicEst}}== |
=={{header|HicEst}}== |
||
< |
<syntaxhighlight lang="hicest"> CHARACTER string*40 |
||
WRITE(Text=string, Format='UCCYY-MM-DD') 0 ! string: 2010-03-13 |
WRITE(Text=string, Format='UCCYY-MM-DD') 0 ! string: 2010-03-13 |
||
Line 2,155: | Line 2,155: | ||
EDIT(Text=string, Right=' ', Mark1, Right=';', Right=3, Mark2, Delete, Insert=', '//cMonth, Right=';', RePLaceby=',') |
EDIT(Text=string, Right=' ', Mark1, Right=';', Right=3, Mark2, Delete, Insert=', '//cMonth, Right=';', RePLaceby=',') |
||
END</ |
END</syntaxhighlight> |
||
=={{header|Icon}} and {{header|Unicon}}== |
=={{header|Icon}} and {{header|Unicon}}== |
||
< |
<syntaxhighlight lang="icon">procedure main() |
||
write(map(&date,"/","-")) |
write(map(&date,"/","-")) |
||
write(&dateline ? tab(find(&date[1:5])+4)) |
write(&dateline ? tab(find(&date[1:5])+4)) |
||
end</ |
end</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,169: | Line 2,169: | ||
=={{header|J}}== |
=={{header|J}}== |
||
Short format using built in formatting: |
Short format using built in formatting: |
||
< |
<syntaxhighlight lang="j"> 6!:0 'YYYY-MM-DD' |
||
2010-08-19</ |
2010-08-19</syntaxhighlight> |
||
Verb to show custom format: |
Verb to show custom format: |
||
< |
<syntaxhighlight lang="j">require 'dates system/packages/misc/datefmt.ijs' |
||
days=:;:'Sunday Monday Tuesday Wednesday Thursday Friday Saturday' |
days=:;:'Sunday Monday Tuesday Wednesday Thursday Friday Saturday' |
||
fmtDate=: [:((days ;@{~ weekday),', ',ms0) 3 {.] |
fmtDate=: [:((days ;@{~ weekday),', ',ms0) 3 {.] |
||
fmtDate 6!:0 '' |
fmtDate 6!:0 '' |
||
Thursday, August 19, 2010</ |
Thursday, August 19, 2010</syntaxhighlight> |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
< |
<syntaxhighlight lang="java"> |
||
import java.util.Calendar; |
import java.util.Calendar; |
||
import java.util.GregorianCalendar; |
import java.util.GregorianCalendar; |
||
Line 2,200: | Line 2,200: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
Better: use a library, see http://sourceforge.net/apps/mediawiki/threeten/index.php?title=ThreeTen |
Better: use a library, see http://sourceforge.net/apps/mediawiki/threeten/index.php?title=ThreeTen |
||
===Java 8 Date Time API=== |
===Java 8 Date Time API=== |
||
< |
<syntaxhighlight lang="java"> |
||
import java.time.LocalDate; |
import java.time.LocalDate; |
||
import java.time.format.DateTimeFormatter; |
import java.time.format.DateTimeFormatter; |
||
Line 2,218: | Line 2,218: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
===Java Util Date API=== |
===Java Util Date API=== |
||
< |
<syntaxhighlight lang="java"> |
||
import java.text.SimpleDateFormat; |
import java.text.SimpleDateFormat; |
||
import java.util.Date; |
import java.util.Date; |
||
Line 2,233: | Line 2,233: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
JavaScript does not have any built-in <code>strftime</code>-type functionality. |
JavaScript does not have any built-in <code>strftime</code>-type functionality. |
||
< |
<syntaxhighlight lang="javascript">var now = new Date(), |
||
weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], |
weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], |
||
months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], |
months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], |
||
Line 2,243: | Line 2,243: | ||
fmt2 = weekdays[now.getDay()] + ', ' + months[now.getMonth()] + ' ' + now.getDate() + ', ' + now.getFullYear(); |
fmt2 = weekdays[now.getDay()] + ', ' + months[now.getMonth()] + ' ' + now.getDate() + ', ' + now.getFullYear(); |
||
console.log(fmt1); |
console.log(fmt1); |
||
console.log(fmt2);</ |
console.log(fmt2);</syntaxhighlight> |
||
<pre>2010-1-12 |
<pre>2010-1-12 |
||
Tuesday, January 12, 2010</pre> |
Tuesday, January 12, 2010</pre> |
||
=={{header|Joy}}== |
=={{header|Joy}}== |
||
<syntaxhighlight lang="joy"> |
|||
<lang Joy> |
|||
DEFINE weekdays == [ "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday" ]; |
DEFINE weekdays == [ "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday" ]; |
||
months == [ "January" "February" "March" "April" "May" "June" "July" "August" |
months == [ "January" "February" "March" "April" "May" "June" "July" "August" |
||
Line 2,258: | Line 2,258: | ||
time localtime [ [8 at pred weekdays of] [", "] [1 at pred months of] [" "] [2 at 'd 1 1 format] |
time localtime [ [8 at pred weekdays of] [", "] [1 at pred months of] [" "] [2 at 'd 1 1 format] |
||
[", "] [0 at 'd 4 4 format] ] [i] map [putchars] step '\n putch pop. |
[", "] [0 at 'd 4 4 format] ] [i] map [putchars] step '\n putch pop. |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|jq}}== |
=={{header|jq}}== |
||
{{works with|jq|with strftime}} |
{{works with|jq|with strftime}} |
||
< |
<syntaxhighlight lang="sh">$ jq -n 'now | (strftime("%Y-%m-%d"), strftime("%A, %B %d, %Y"))' |
||
"2015-07-02" |
"2015-07-02" |
||
"Thursday, July 02, 2015"</ |
"Thursday, July 02, 2015"</syntaxhighlight> |
||
WARNING: prior to July 2, 2015, there was a bug in jq affecting the display of the "day of week" (wday) and the "day of the year" (yday). |
WARNING: prior to July 2, 2015, there was a bug in jq affecting the display of the "day of week" (wday) and the "day of the year" (yday). |
||
Line 2,271: | Line 2,271: | ||
{{works with|Julia|0.6}} |
{{works with|Julia|0.6}} |
||
< |
<syntaxhighlight lang="julia">ts = Dates.today() |
||
println("Today's date is:") |
println("Today's date is:") |
||
println("\t$ts") |
println("\t$ts") |
||
println("\t", Dates.format(ts, "E, U dd, yyyy"))</ |
println("\t", Dates.format(ts, "E, U dd, yyyy"))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,283: | Line 2,283: | ||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
< |
<syntaxhighlight lang="scala">// version 1.0.6 |
||
import java.util.GregorianCalendar |
import java.util.GregorianCalendar |
||
Line 2,291: | Line 2,291: | ||
println("%tF".format(now)) |
println("%tF".format(now)) |
||
println("%tA, %1\$tB %1\$te, %1\$tY".format(now)) |
println("%tA, %1\$tB %1\$te, %1\$tY".format(now)) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,301: | Line 2,301: | ||
=={{header|langur}}== |
=={{header|langur}}== |
||
{{works with|langur|0.10.1}} |
{{works with|langur|0.10.1}} |
||
< |
<syntaxhighlight lang="langur">var .now = dt// |
||
var .format1 = "2006-01-02" |
var .format1 = "2006-01-02" |
||
var .format2 = "Monday, January 2, 2006" |
var .format2 = "Monday, January 2, 2006" |
||
writeln $"\.now:dt.format1;" |
writeln $"\.now:dt.format1;" |
||
writeln $"\.now:dt.format2;"</ |
writeln $"\.now:dt.format2;"</syntaxhighlight> |
||
{{works with|langur|0.9.3}} |
{{works with|langur|0.9.3}} |
||
< |
<syntaxhighlight lang="langur">var .now = dt// |
||
writeln $"\.now:dt(2006-01-02);" |
writeln $"\.now:dt(2006-01-02);" |
||
writeln $"\.now:dt(Monday, January 2, 2006);"</ |
writeln $"\.now:dt(Monday, January 2, 2006);"</syntaxhighlight> |
||
{{works with|langur|0.9}} |
{{works with|langur|0.9}} |
||
< |
<syntaxhighlight lang="langur">writeln toString dt//, "2006-01-02" |
||
writeln toString dt//, "Monday, January 2, 2006"</ |
writeln toString dt//, "Monday, January 2, 2006"</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,335: | Line 2,335: | ||
=={{header|Lasso}}== |
=={{header|Lasso}}== |
||
<syntaxhighlight lang="lasso"> |
|||
<lang Lasso> |
|||
date('11/10/2007')->format('%Q') // 2007-11-10 |
date('11/10/2007')->format('%Q') // 2007-11-10 |
||
date('11/10/2007')->format('EEEE, MMMM d, YYYY') //Saturday, November 10, 2007 |
date('11/10/2007')->format('EEEE, MMMM d, YYYY') //Saturday, November 10, 2007 |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Liberty BASIC}}== |
=={{header|Liberty BASIC}}== |
||
< |
<syntaxhighlight lang="lb">'Display the current date in the formats of "2007-11-10" |
||
d$=date$("yyyy/mm/dd") |
d$=date$("yyyy/mm/dd") |
||
print word$(d$,1,"/")+"-"+word$(d$,2,"/")+"-"+word$(d$,3,"/") |
print word$(d$,1,"/")+"-"+word$(d$,2,"/")+"-"+word$(d$,3,"/") |
||
Line 2,364: | Line 2,364: | ||
monthLong$="January February March April May June July August September October November December" |
monthLong$="January February March April May June July August September October November December" |
||
print word$(weekDay$,theDay+1);", ";word$(monthLong$,month);" ";day;", ";year</ |
print word$(weekDay$,theDay+1);", ";word$(monthLong$,month);" ";day;", ";year</syntaxhighlight> |
||
=={{header|LiveCode}}== |
=={{header|LiveCode}}== |
||
< |
<syntaxhighlight lang="livecode">on mouseUp pButtonNumber |
||
put the date into tDate |
put the date into tDate |
||
convert tDate to dateItems |
convert tDate to dateItems |
||
put item 1 of tDate & "-" & item 2 of tDate & "-" & item 3 of tDate & return into tMyFormattedDate |
put item 1 of tDate & "-" & item 2 of tDate & "-" & item 3 of tDate & return into tMyFormattedDate |
||
put tMyFormattedDate & the long date |
put tMyFormattedDate & the long date |
||
end mouseUp </ |
end mouseUp </syntaxhighlight> |
||
=={{header|Logo}}== |
=={{header|Logo}}== |
||
{{works with|UCB Logo}} |
{{works with|UCB Logo}} |
||
A bit of a cheat since Logo has no standard built-in time and date functions, but UCB Logo can call out to the shell, so: |
A bit of a cheat since Logo has no standard built-in time and date functions, but UCB Logo can call out to the shell, so: |
||
< |
<syntaxhighlight lang="logo"> |
||
print first shell [date +%F] |
print first shell [date +%F] |
||
print first shell [date +"%A, %B %d, %Y"] |
print first shell [date +"%A, %B %d, %Y"] |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{Out}} |
{{Out}} |
||
<pre>2020-09-16 |
<pre>2020-09-16 |
||
Line 2,387: | Line 2,387: | ||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
< |
<syntaxhighlight lang="lua">print( os.date( "%Y-%m-%d" ) ) |
||
print( os.date( "%A, %B %d, %Y" ) )</ |
print( os.date( "%A, %B %d, %Y" ) )</syntaxhighlight> |
||
=={{header|M2000 Interpreter}}== |
=={{header|M2000 Interpreter}}== |
||
<syntaxhighlight lang="m2000 interpreter"> |
|||
<lang M2000 Interpreter> |
|||
Print str$(today, "yyyy-mm-dd") |
Print str$(today, "yyyy-mm-dd") |
||
Print str$(today, "dddd, mmm, dd, yyyy") |
Print str$(today, "dddd, mmm, dd, yyyy") |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Maple}}== |
=={{header|Maple}}== |
||
<syntaxhighlight lang="maple"> |
|||
<lang Maple> |
|||
with(StringTools); |
with(StringTools); |
||
FormatTime("%Y-%m-%d") |
FormatTime("%Y-%m-%d") |
||
FormatTime("%A,%B %d, %y") |
FormatTime("%A,%B %d, %y") |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">DateString[{"Year", "-", "Month", "-", "Day"}] |
||
DateString[{"DayName", ", ", "MonthName", " ", "Day", ", ", "Year"}]</ |
DateString[{"DayName", ", ", "MonthName", " ", "Day", ", ", "Year"}]</syntaxhighlight> |
||
=={{header|MATLAB}} / {{header|Octave}}== |
=={{header|MATLAB}} / {{header|Octave}}== |
||
< |
<syntaxhighlight lang="matlab">>> datestr(now,'yyyy-mm-dd') |
||
ans = |
ans = |
||
Line 2,419: | Line 2,419: | ||
ans = |
ans = |
||
Friday, June 18, 2010</ |
Friday, June 18, 2010</syntaxhighlight> |
||
=={{header|min}}== |
=={{header|min}}== |
||
{{works with|min|0.19.3}} |
{{works with|min|0.19.3}} |
||
< |
<syntaxhighlight lang="min">("YYYY-MM-dd" "dddd, MMMM dd, YYYY") ('timestamp dip tformat puts!) foreach</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 2,431: | Line 2,431: | ||
=={{header|mIRC Scripting Language}}== |
=={{header|mIRC Scripting Language}}== |
||
< |
<syntaxhighlight lang="mirc">echo -ag $time(yyyy-mm-dd) |
||
echo -ag $time(dddd $+ $chr(44) mmmm dd $+ $chr(44) yyyy)</ |
echo -ag $time(dddd $+ $chr(44) mmmm dd $+ $chr(44) yyyy)</syntaxhighlight> |
||
=={{header|MUMPS}}== |
=={{header|MUMPS}}== |
||
{{works with|MUMPS|Intersystems' Caché|(all versions)}} |
{{works with|MUMPS|Intersystems' Caché|(all versions)}} |
||
Functions starting with 'Z' or '$Z' are implementation specific. |
Functions starting with 'Z' or '$Z' are implementation specific. |
||
< |
<syntaxhighlight lang="mumps">DTZ |
||
WRITE !,"Date format 3: ",$ZDATE($H,3) |
WRITE !,"Date format 3: ",$ZDATE($H,3) |
||
WRITE !,"Or ",$ZDATE($H,12),", ",$ZDATE($H,9) |
WRITE !,"Or ",$ZDATE($H,12),", ",$ZDATE($H,9) |
||
QUIT</ |
QUIT</syntaxhighlight> |
||
<p>MUMPS contains the integer number of days since December 31, 1840 in the first part of the system variable $HOROLOG.</p> |
<p>MUMPS contains the integer number of days since December 31, 1840 in the first part of the system variable $HOROLOG.</p> |
||
{{works with|MUMPS|all}} |
{{works with|MUMPS|all}} |
||
< |
<syntaxhighlight lang="mumps">DTM(H) |
||
;You can pass an integer, but the default is to use today's value |
;You can pass an integer, but the default is to use today's value |
||
SET:$DATA(H)=0 H=$HOROLOG |
SET:$DATA(H)=0 H=$HOROLOG |
||
Line 2,463: | Line 2,463: | ||
WRITE !,$P(DN,",",DOW),", ",$P(MN,",",MO)," ",DA,", ",YR |
WRITE !,$P(DN,",",DOW),", ",$P(MN,",",MO)," ",DA,", ",YR |
||
KILL Y,YR,RD,MC,MO,DA,MN,DN,DOW |
KILL Y,YR,RD,MC,MO,DA,MN,DN,DOW |
||
QUIT</ |
QUIT</syntaxhighlight> |
||
Demos:<pre> |
Demos:<pre> |
||
USER>D DTM^ROSETTA |
USER>D DTM^ROSETTA |
||
Line 2,480: | Line 2,480: | ||
=={{header|Nanoquery}}== |
=={{header|Nanoquery}}== |
||
< |
<syntaxhighlight lang="nanoquery">import Nanoquery.Util |
||
d = new(Date) |
d = new(Date) |
||
println d.getYear() + "-" + d.getMonth() + "-" + d.getDay() |
println d.getYear() + "-" + d.getMonth() + "-" + d.getDay() |
||
println d.getDayOfWeek() + ", " + d.getMonthName() + " " + d.getDay() + ", " + d.getYear()</ |
println d.getDayOfWeek() + ", " + d.getMonthName() + " " + d.getDay() + ", " + d.getYear()</syntaxhighlight> |
||
=={{header|Neko}}== |
=={{header|Neko}}== |
||
<syntaxhighlight lang="actionscript">/** |
|||
<lang ActionScript>/** |
|||
<doc> |
<doc> |
||
<h2>Date format</h2> |
<h2>Date format</h2> |
||
Line 2,500: | Line 2,500: | ||
var now = date_now() |
var now = date_now() |
||
$print(date_format(now, "%F"), "\n") |
$print(date_format(now, "%F"), "\n") |
||
$print(date_format(now, "%A, %B %d, %Y"), "\n")</ |
$print(date_format(now, "%A, %B %d, %Y"), "\n")</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>prompt$ nekoc date-format.neko |
<pre>prompt$ nekoc date-format.neko |
||
Line 2,508: | Line 2,508: | ||
=={{header|NetRexx}}== |
=={{header|NetRexx}}== |
||
<syntaxhighlight lang="netrexx"> |
|||
<lang NetRexx> |
|||
import java.text.SimpleDateFormat |
import java.text.SimpleDateFormat |
||
say SimpleDateFormat("yyyy-MM-dd").format(Date()) |
say SimpleDateFormat("yyyy-MM-dd").format(Date()) |
||
say SimpleDateFormat("EEEE, MMMM dd, yyyy").format(Date()) |
say SimpleDateFormat("EEEE, MMMM dd, yyyy").format(Date()) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre>2019-02-10 |
<pre>2019-02-10 |
||
Line 2,518: | Line 2,518: | ||
=={{header|NewLISP}}== |
=={{header|NewLISP}}== |
||
< |
<syntaxhighlight lang="newlisp">; file: date-format.lsp |
||
; url: http://rosettacode.org/wiki/Date_format |
; url: http://rosettacode.org/wiki/Date_format |
||
; author: oofoe 2012-02-01 |
; author: oofoe 2012-02-01 |
||
Line 2,551: | Line 2,551: | ||
(println "long: " (date (date-value) 0 "%A, %B %#d, %Y")) |
(println "long: " (date (date-value) 0 "%A, %B %#d, %Y")) |
||
(exit)</ |
(exit)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,561: | Line 2,561: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang="nim">import times |
||
var t = now() |
var t = now() |
||
echo(t.format("yyyy-MM-dd")) |
echo(t.format("yyyy-MM-dd")) |
||
echo(t.format("dddd',' MMMM d',' yyyy"))</ |
echo(t.format("dddd',' MMMM d',' yyyy"))</syntaxhighlight> |
||
=={{header|Objeck}}== |
=={{header|Objeck}}== |
||
< |
<syntaxhighlight lang="objeck"> |
||
use IO; |
use IO; |
||
use Time; |
use Time; |
||
Line 2,584: | Line 2,584: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 2,593: | Line 2,593: | ||
=={{header|Objective-C}}== |
=={{header|Objective-C}}== |
||
< |
<syntaxhighlight lang="objc">NSLog(@"%@", [NSDate date]); |
||
NSLog(@"%@", [[NSDate date] descriptionWithCalendarFormat:@"%Y-%m-%d" timeZone:nil locale:nil]); |
NSLog(@"%@", [[NSDate date] descriptionWithCalendarFormat:@"%Y-%m-%d" timeZone:nil locale:nil]); |
||
NSLog(@"%@", [[NSDate date] descriptionWithCalendarFormat:@"%A, %B %d, %Y" timeZone:nil locale:nil]);</ |
NSLog(@"%@", [[NSDate date] descriptionWithCalendarFormat:@"%A, %B %d, %Y" timeZone:nil locale:nil]);</syntaxhighlight> |
||
{{works with|Mac OS X|10.4+}} |
{{works with|Mac OS X|10.4+}} |
||
{{works with|iOS}} |
{{works with|iOS}} |
||
< |
<syntaxhighlight lang="objc">NSLog(@"%@", [NSDate date]); |
||
NSDateFormatter *dateFormatter = [[NSDateFormat alloc] init]; |
NSDateFormatter *dateFormatter = [[NSDateFormat alloc] init]; |
||
[dateFormatter setDateFormat:@"yyyy-MM-dd"]; |
[dateFormatter setDateFormat:@"yyyy-MM-dd"]; |
||
NSLog(@"%@", [dateFormatter stringFromDate:[NSDate date]]); |
NSLog(@"%@", [dateFormatter stringFromDate:[NSDate date]]); |
||
[dateFormatter setDateFormat:@"EEEE, MMMM d, yyyy"]; |
[dateFormatter setDateFormat:@"EEEE, MMMM d, yyyy"]; |
||
NSLog(@"%@", [dateFormatter stringFromDate:[NSDate date]]);</ |
NSLog(@"%@", [dateFormatter stringFromDate:[NSDate date]]);</syntaxhighlight> |
||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
< |
<syntaxhighlight lang="ocaml"># #load "unix.cma";; |
||
# open Unix;; |
# open Unix;; |
||
Line 2,620: | Line 2,620: | ||
# Printf.sprintf "%d-%02d-%02d" (1900 + gmt.tm_year) (1 + gmt.tm_mon) gmt.tm_mday ;; |
# Printf.sprintf "%d-%02d-%02d" (1900 + gmt.tm_year) (1 + gmt.tm_mon) gmt.tm_mday ;; |
||
- : string = "2008-08-29"</ |
- : string = "2008-08-29"</syntaxhighlight> |
||
< |
<syntaxhighlight lang="ocaml">let months = [| "January"; "February"; "March"; "April"; "May"; "June"; |
||
"July"; "August"; "September"; "October"; "November"; "December" |] |
"July"; "August"; "September"; "October"; "November"; "December" |] |
||
Line 2,633: | Line 2,633: | ||
gmt.tm_mday |
gmt.tm_mday |
||
(1900 + gmt.tm_year) ;; |
(1900 + gmt.tm_year) ;; |
||
- : string = "Friday, August 29, 2008"</ |
- : string = "Friday, August 29, 2008"</syntaxhighlight> |
||
=={{header|ooRexx}}== |
=={{header|ooRexx}}== |
||
< |
<syntaxhighlight lang="oorexx">/* REXX */ |
||
dats='20071123' |
dats='20071123' |
||
Say date('I',dats,'S') |
Say date('I',dats,'S') |
||
Line 2,643: | Line 2,643: | ||
dati=date('I') |
dati=date('I') |
||
Say dati |
Say dati |
||
Say date('W',dati,'I')',' date('M',dati,'I') translate('ij, abcd',dati,'abcdefghij')</ |
Say date('W',dati,'I')',' date('M',dati,'I') translate('ij, abcd',dati,'abcdefghij')</syntaxhighlight> |
||
{{out}}2007-11-23 |
{{out}}2007-11-23 |
||
Friday, November 23, 2007 |
Friday, November 23, 2007 |
||
Line 2,651: | Line 2,651: | ||
=={{header|OxygenBasic}}== |
=={{header|OxygenBasic}}== |
||
< |
<syntaxhighlight lang="oxygenbasic"> |
||
extern lib "kernel32.dll" |
extern lib "kernel32.dll" |
||
Line 2,683: | Line 2,683: | ||
print "" t.wYear "-" month "-" day |
print "" t.wYear "-" month "-" day |
||
print WeekDay[t.wDayOfWeek+1 and 7 ] " " MonthName[t.wMonth and 31] " " t.wDay " " t.wYear |
print WeekDay[t.wDayOfWeek+1 and 7 ] " " MonthName[t.wMonth and 31] " " t.wDay " " t.wYear |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Oz}}== |
=={{header|Oz}}== |
||
Getting the current local date is easy, but we have to do the formatting manually. |
Getting the current local date is easy, but we have to do the formatting manually. |
||
< |
<syntaxhighlight lang="oz">declare |
||
WeekDays = unit(0:"Sunday" "Monday" "Tuesday" "Wednesday" |
WeekDays = unit(0:"Sunday" "Monday" "Tuesday" "Wednesday" |
||
"Thursday" "Friday" "Saturday") |
"Thursday" "Friday" "Saturday") |
||
Line 2,712: | Line 2,712: | ||
in |
in |
||
{System.showInfo {DateISO {OS.localTime}}} |
{System.showInfo {DateISO {OS.localTime}}} |
||
{System.showInfo {DateLong {OS.localTime}}}</ |
{System.showInfo {DateLong {OS.localTime}}}</syntaxhighlight> |
||
=={{header|Pascal}}== |
=={{header|Pascal}}== |
||
{{works with|Turbo Pascal|5.5}} |
{{works with|Turbo Pascal|5.5}} |
||
< |
<syntaxhighlight lang="pascal">program dateform; |
||
uses DOS; |
uses DOS; |
||
Line 2,770: | Line 2,770: | ||
mname := m2s(mo); dname := d2s(dow); |
mname := m2s(mo); dname := d2s(dow); |
||
writeln(dname,', ',mname,' ',dy,', ',yr) |
writeln(dname,', ',mname,' ',dy,', ',yr) |
||
end.</ |
end.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,778: | Line 2,778: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{libheader|POSIX}} |
{{libheader|POSIX}} |
||
< |
<syntaxhighlight lang="perl">use POSIX; |
||
print strftime('%Y-%m-%d', 0, 0, 0, 10, 10, 107), "\n"; |
print strftime('%Y-%m-%d', 0, 0, 0, 10, 10, 107), "\n"; |
||
print strftime('%A, %B %d, %Y', 0, 0, 0, 10, 10, 107), "\n";</ |
print strftime('%A, %B %d, %Y', 0, 0, 0, 10, 10, 107), "\n";</syntaxhighlight> |
||
{{out}} with locales '''C''': |
{{out}} with locales '''C''': |
||
Line 2,792: | Line 2,792: | ||
Actual date: |
Actual date: |
||
< |
<syntaxhighlight lang="perl">use POSIX; |
||
print strftime('%Y-%m-%d', localtime), "\n"; |
print strftime('%Y-%m-%d', localtime), "\n"; |
||
print strftime('%A, %B %d, %Y', localtime), "\n";</ |
print strftime('%A, %B %d, %Y', localtime), "\n";</syntaxhighlight> |
||
{{out}} with locales '''C''': |
{{out}} with locales '''C''': |
||
Line 2,803: | Line 2,803: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
{{libheader|Phix/basics}} |
{{libheader|Phix/basics}} |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
||
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">\</span><span style="color: #004080;">timedate</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> |
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">\</span><span style="color: #004080;">timedate</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> |
||
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">format_timedate</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">date</span><span style="color: #0000FF;">(),</span><span style="color: #008000;">"YYYY-MM-DD"</span><span style="color: #0000FF;">)</span> |
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">format_timedate</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">date</span><span style="color: #0000FF;">(),</span><span style="color: #008000;">"YYYY-MM-DD"</span><span style="color: #0000FF;">)</span> |
||
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">format_timedate</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">date</span><span style="color: #0000FF;">(),</span><span style="color: #008000;">"Dddd, Mmmm d, YYYY"</span><span style="color: #0000FF;">)</span> |
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">format_timedate</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">date</span><span style="color: #0000FF;">(),</span><span style="color: #008000;">"Dddd, Mmmm d, YYYY"</span><span style="color: #0000FF;">)</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 2,817: | Line 2,817: | ||
=={{header|PHP}}== |
=={{header|PHP}}== |
||
Formatting rules: http://www.php.net/date |
Formatting rules: http://www.php.net/date |
||
< |
<syntaxhighlight lang="php"><?php |
||
echo date('Y-m-d', time())."\n"; |
echo date('Y-m-d', time())."\n"; |
||
echo date('l, F j, Y', time())."\n"; |
echo date('l, F j, Y', time())."\n"; |
||
?></ |
?></syntaxhighlight> |
||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
< |
<syntaxhighlight lang="picolisp">(let (Date (date) Lst (date Date)) |
||
(prinl (dat$ Date "-")) # 2010-02-19 |
(prinl (dat$ Date "-")) # 2010-02-19 |
||
(prinl # Friday, February 19, 2010 |
(prinl # Friday, February 19, 2010 |
||
Line 2,832: | Line 2,832: | ||
(caddr Lst) |
(caddr Lst) |
||
", " |
", " |
||
(car Lst) ) )</ |
(car Lst) ) )</syntaxhighlight> |
||
=={{header|Pike}}== |
=={{header|Pike}}== |
||
<syntaxhighlight lang="pike"> |
|||
<lang Pike> |
|||
object cal = Calendar.ISO.Day(); |
object cal = Calendar.ISO.Day(); |
||
write( cal->format_ymd() +"\n" ); |
write( cal->format_ymd() +"\n" ); |
||
Line 2,844: | Line 2,844: | ||
cal->year_no()); |
cal->year_no()); |
||
write( special +"\n" ); |
write( special +"\n" ); |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{Out}} |
{{Out}} |
||
<pre> |
<pre> |
||
Line 2,853: | Line 2,853: | ||
=={{header|PL/I}}== |
=={{header|PL/I}}== |
||
===Version 1=== |
===Version 1=== |
||
< |
<syntaxhighlight lang="pli">df: proc Options(main); |
||
declare day_of_week(7) character (9) varying initial( |
declare day_of_week(7) character (9) varying initial( |
||
'Sunday','Monday','Tuesday','Wednesday', |
'Sunday','Monday','Tuesday','Wednesday', |
||
Line 2,867: | Line 2,867: | ||
put edit(substr(today,1,3),' ',substr(today,4,2),', ', |
put edit(substr(today,1,3),' ',substr(today,4,2),', ', |
||
substr(today,6,4))(A); |
substr(today,6,4))(A); |
||
end;</ |
end;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>2013-11-02 |
<pre>2013-11-02 |
||
Line 2,873: | Line 2,873: | ||
===Version 2=== |
===Version 2=== |
||
< |
<syntaxhighlight lang="pl/i"> df: proc Options(Main); |
||
declare day_of_week(7) character(9) varying initial( |
declare day_of_week(7) character(9) varying initial( |
||
'Sunday','Monday','Tuesday','Wednesday', |
'Sunday','Monday','Tuesday','Wednesday', |
||
Line 2,888: | Line 2,888: | ||
put edit(month(substr(today,1,2)),' ',substr(today,3,2),', ', |
put edit(month(substr(today,1,2)),' ',substr(today,3,2),', ', |
||
substr(today,5,4))(A); |
substr(today,5,4))(A); |
||
End;</ |
End;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>2013-11-02 |
<pre>2013-11-02 |
||
Line 2,894: | Line 2,894: | ||
=={{header|PowerShell}}== |
=={{header|PowerShell}}== |
||
< |
<syntaxhighlight lang="powershell">"{0:yyyy-MM-dd}" -f (Get-Date) |
||
"{0:dddd, MMMM d, yyyy}" -f (Get-Date) |
"{0:dddd, MMMM d, yyyy}" -f (Get-Date) |
||
# or |
# or |
||
(Get-Date).ToString("yyyy-MM-dd") |
(Get-Date).ToString("yyyy-MM-dd") |
||
(Get-Date).ToString("dddd, MMMM d, yyyy")</ |
(Get-Date).ToString("dddd, MMMM d, yyyy")</syntaxhighlight> |
||
''Note:'' The names of months and days follow the currently set locale but otherwise the format is unchanged. |
''Note:'' The names of months and days follow the currently set locale but otherwise the format is unchanged. |
||
Line 2,905: | Line 2,905: | ||
{{works with|SWI-Prolog|6}} |
{{works with|SWI-Prolog|6}} |
||
< |
<syntaxhighlight lang="prolog"> |
||
display_date :- |
display_date :- |
||
get_time(Time), |
get_time(Time), |
||
Line 2,911: | Line 2,911: | ||
format_time(atom(Long), '%A, %B %d, %Y', Time), |
format_time(atom(Long), '%A, %B %d, %Y', Time), |
||
format('~w~n~w~n', [Short, Long]). |
format('~w~n~w~n', [Short, Long]). |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
{{works with|PureBasic|4.41}} |
{{works with|PureBasic|4.41}} |
||
< |
<syntaxhighlight lang="purebasic">;Declare Procedures |
||
Declare.s MonthInText() |
Declare.s MonthInText() |
||
Declare.s DayInText() |
Declare.s DayInText() |
||
Line 2,955: | Line 2,955: | ||
EndSelect |
EndSelect |
||
ProcedureReturn m$ |
ProcedureReturn m$ |
||
EndProcedure</ |
EndProcedure</syntaxhighlight> |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
Formatting rules: http://docs.python.org/lib/module-time.html (strftime) |
Formatting rules: http://docs.python.org/lib/module-time.html (strftime) |
||
< |
<syntaxhighlight lang="python">import datetime |
||
today = datetime.date.today() |
today = datetime.date.today() |
||
# The first requested format is a method of datetime objects: |
# The first requested format is a method of datetime objects: |
||
Line 2,973: | Line 2,973: | ||
# Since Python 3.6, f-strings allow the value to be inserted inline |
# Since Python 3.6, f-strings allow the value to be inserted inline |
||
f"The date is {d:%A, %B %d, %Y}" |
f"The date is {d:%A, %B %d, %Y}" |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|R}}== |
=={{header|R}}== |
||
strftime is short for "string format time". |
strftime is short for "string format time". |
||
< |
<syntaxhighlight lang="rsplus">now <- Sys.time() |
||
strftime(now, "%Y-%m-%d") |
strftime(now, "%Y-%m-%d") |
||
strftime(now, "%A, %B %d, %Y")</ |
strftime(now, "%A, %B %d, %Y")</syntaxhighlight> |
||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
Line 2,993: | Line 2,993: | ||
See: http://srfi.schemers.org/srfi-19/srfi-19.html |
See: http://srfi.schemers.org/srfi-19/srfi-19.html |
||
< |
<syntaxhighlight lang="racket">#lang racket |
||
(require srfi/19) |
(require srfi/19) |
||
Line 3,005: | Line 3,005: | ||
(displayln (date->string (current-date) "~A, ~B ~d, ~Y")) |
(displayln (date->string (current-date) "~A, ~B ~d, ~Y")) |
||
;;; ~e is space padded day of month: |
;;; ~e is space padded day of month: |
||
(displayln (date->string (current-date) "~A, ~B ~e, ~Y"))</ |
(displayln (date->string (current-date) "~A, ~B ~e, ~Y"))</syntaxhighlight> |
||
both ~d and ~e satisfy the format required, since the "10" part of that date is 2-digit |
both ~d and ~e satisfy the format required, since the "10" part of that date is 2-digit |
||
Line 3,016: | Line 3,016: | ||
(formerly Perl 6) |
(formerly Perl 6) |
||
{{libheader|DateTime::Format}} |
{{libheader|DateTime::Format}} |
||
<lang |
<syntaxhighlight lang="raku" line>use DateTime::Format; |
||
my $dt = DateTime.now; |
my $dt = DateTime.now; |
||
say strftime('%Y-%m-%d', $dt); |
say strftime('%Y-%m-%d', $dt); |
||
say strftime('%A, %B %d, %Y', $dt);</ |
say strftime('%A, %B %d, %Y', $dt);</syntaxhighlight> |
||
The built-in Date and DateTime classes both offer support for the ISO format: |
The built-in Date and DateTime classes both offer support for the ISO format: |
||
<lang |
<syntaxhighlight lang="raku" line>my $d = Date.today; |
||
say $d.yyyy-mm-dd;</ |
say $d.yyyy-mm-dd;</syntaxhighlight> |
||
They don't include the longer format specified in the task, but you can always roll your own formatter instead of importing the library: |
They don't include the longer format specified in the task, but you can always roll your own formatter instead of importing the library: |
||
<lang |
<syntaxhighlight lang="raku" line>my @months = <January February March April May June July |
||
August September October November December>; |
August September October November December>; |
||
my @days = <Monday Tuesday Wednesday Thursday Friday Saturday Sunday>; |
my @days = <Monday Tuesday Wednesday Thursday Friday Saturday Sunday>; |
||
Line 3,037: | Line 3,037: | ||
say $d.yyyy-mm-dd; # still works |
say $d.yyyy-mm-dd; # still works |
||
say $d; # uses our formatter sub</ |
say $d; # uses our formatter sub</syntaxhighlight> |
||
=={{header|Raven}}== |
=={{header|Raven}}== |
||
<lang |
<syntaxhighlight lang="raven">time int as today</syntaxhighlight> |
||
Short form: |
Short form: |
||
< |
<syntaxhighlight lang="raven">today '%Y-%m-%d' date</syntaxhighlight> |
||
Long form: |
Long form: |
||
< |
<syntaxhighlight lang="raven">today '%A, %B %d, %Y' date</syntaxhighlight> |
||
=={{header|REBOL}}== |
=={{header|REBOL}}== |
||
< |
<syntaxhighlight lang="rebol">REBOL [ |
||
Title: "Date Formatting" |
Title: "Date Formatting" |
||
URL: http://rosettacode.org/wiki/Date_format |
URL: http://rosettacode.org/wiki/Date_format |
||
Line 3,073: | Line 3,073: | ||
pick system/locale/months now/month " " |
pick system/locale/months now/month " " |
||
now/day ", " now/year |
now/day ", " now/year |
||
]</ |
]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 3,080: | Line 3,080: | ||
Sunday, December 6, 2009</pre> |
Sunday, December 6, 2009</pre> |
||
=={{header|RED}}== |
=={{header|RED}}== |
||
<syntaxhighlight lang="red"> |
|||
<lang RED> |
|||
Red [] |
Red [] |
||
;; zeropad |
;; zeropad |
||
Line 3,089: | Line 3,089: | ||
print rejoin [d/year "-" f2n d/month "-" f2n d/day] |
print rejoin [d/year "-" f2n d/month "-" f2n d/day] |
||
print rejoin [system/locale/days/(d/weekday) ", " system/locale/months/(d/month) " " f2n d/day ", " d/year] |
print rejoin [system/locale/days/(d/weekday) ", " system/locale/months/(d/month) " " f2n d/day ", " d/year] |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}}<pre>2020-03-25 |
{{out}}<pre>2020-03-25 |
||
Wednesday, March 25, 2020 |
Wednesday, March 25, 2020 |
||
Line 3,097: | Line 3,097: | ||
<br>It's up to the programmer to choose whatever version of the '''date''' BIF that best serves the purpose. |
<br>It's up to the programmer to choose whatever version of the '''date''' BIF that best serves the purpose. |
||
===idiomatic version=== |
===idiomatic version=== |
||
< |
<syntaxhighlight lang="rexx">/*REXX pgm shows current date: yyyy-mm-dd & Dayofweek, Month dd, yyyy*/ |
||
x = date('S') /*get current date as yyyymmdd */ |
x = date('S') /*get current date as yyyymmdd */ |
||
yyyy = left(x,4) /*pick off year (4 digs).*/ |
yyyy = left(x,4) /*pick off year (4 digs).*/ |
||
Line 3,108: | Line 3,108: | ||
zdd = dd+0 /*remove leading zero from DD */ |
zdd = dd+0 /*remove leading zero from DD */ |
||
say weekday',' month zdd"," yyyy /*format date as: Month dd, yyyy*/ |
say weekday',' month zdd"," yyyy /*format date as: Month dd, yyyy*/ |
||
/*stick a fork in it, we're done.*/</ |
/*stick a fork in it, we're done.*/</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 3,116: | Line 3,116: | ||
===compact version=== |
===compact version=== |
||
< |
<syntaxhighlight lang="rexx">/*REXX pgm shows current date: yyyy-mm-dd & Dayofweek, Month dd, yyyy*/ |
||
/* ╔══════════════════════════════════════════════════════════════════╗ |
/* ╔══════════════════════════════════════════════════════════════════╗ |
||
║ function returns a specific example ║ |
║ function returns a specific example ║ |
||
Line 3,143: | Line 3,143: | ||
say date('W')"," date('M') word(date(), 1)"," yyyy |
say date('W')"," date('M') word(date(), 1)"," yyyy |
||
/* [↑] dayofweek Month dd, yyyy*/ |
/* [↑] dayofweek Month dd, yyyy*/ |
||
/*stick a fork in it, we're done.*/</ |
/*stick a fork in it, we're done.*/</syntaxhighlight> |
||
'''output''' would be the same as the 1<sup>st</sup> version. |
'''output''' would be the same as the 1<sup>st</sup> version. |
||
===modern version=== |
===modern version=== |
||
This version can be used with those REXXes that support the '''I''' (ISO) parameter for the '''date''' BIF. |
This version can be used with those REXXes that support the '''I''' (ISO) parameter for the '''date''' BIF. |
||
< |
<syntaxhighlight lang="rexx">/*REXX pgm shows current date: yyyy-mm-dd & Dayofweek, Month dd, yyyy*/ |
||
say date('I') /*yyyy-mm-dd with leading zeroes.*/ |
say date('I') /*yyyy-mm-dd with leading zeroes.*/ |
||
Line 3,154: | Line 3,154: | ||
/* [↑] dayofweek Month dd, yyyy*/ |
/* [↑] dayofweek Month dd, yyyy*/ |
||
/*stick a fork in it, we're done.*/ |
/*stick a fork in it, we're done.*/ |
||
</syntaxhighlight> |
|||
</lang> |
|||
'''output''' would be the same as the 1<sup>st</sup> version. |
'''output''' would be the same as the 1<sup>st</sup> version. |
||
<br><br> |
<br><br> |
||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
<syntaxhighlight lang="c"> |
|||
<lang C> |
|||
dateStr = date() |
dateStr = date() |
||
date1 = timelist()[19] + "-" + timelist()[10] + "-" + timelist()[6] |
date1 = timelist()[19] + "-" + timelist()[10] + "-" + timelist()[6] |
||
Line 3,194: | Line 3,194: | ||
*/ |
*/ |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 3,205: | Line 3,205: | ||
Formatting rules: [//www.ruby-doc.org/core/Time.html#method-i-strftime Time#strftime] |
Formatting rules: [//www.ruby-doc.org/core/Time.html#method-i-strftime Time#strftime] |
||
< |
<syntaxhighlight lang="ruby">puts Time.now |
||
puts Time.now.strftime('%Y-%m-%d') |
puts Time.now.strftime('%Y-%m-%d') |
||
puts Time.now.strftime('%F') # same as %Y-%m-%d (ISO 8601 date formats) |
puts Time.now.strftime('%F') # same as %Y-%m-%d (ISO 8601 date formats) |
||
puts Time.now.strftime('%A, %B %d, %Y')</ |
puts Time.now.strftime('%A, %B %d, %Y')</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 3,218: | Line 3,218: | ||
=={{header|Run BASIC}}== |
=={{header|Run BASIC}}== |
||
< |
<syntaxhighlight lang="runbasic">'Display the current date in the formats of "2007-11-10" and "Sunday, November 10, 2007". |
||
print date$("yyyy-mm-dd") |
print date$("yyyy-mm-dd") |
||
print date$("dddd");", "; 'return full day of the week (eg. Wednesday |
print date$("dddd");", "; 'return full day of the week (eg. Wednesday |
||
print date$("mmmm");" "; 'return full month name (eg. March) |
print date$("mmmm");" "; 'return full month name (eg. March) |
||
print date$("dd, yyyy") 'return day, year</ |
print date$("dd, yyyy") 'return day, year</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 3,231: | Line 3,231: | ||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
Using <code>chrono 0.4.6</code> |
Using <code>chrono 0.4.6</code> |
||
< |
<syntaxhighlight lang="rust">fn main() { |
||
let now = chrono::Utc::now(); |
let now = chrono::Utc::now(); |
||
println!("{}", now.format("%Y-%m-%d")); |
println!("{}", now.format("%Y-%m-%d")); |
||
println!("{}", now.format("%A, %B %d, %Y")); |
println!("{}", now.format("%A, %B %d, %Y")); |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
< |
<syntaxhighlight lang="scala">val now=new Date() |
||
println("%tF".format(now)) |
println("%tF".format(now)) |
||
println("%1$tA, %1$tB %1$td, %1$tY".format(now))</ |
println("%1$tA, %1$tB %1$td, %1$tY".format(now))</syntaxhighlight> |
||
=={{header|Scheme}}== |
=={{header|Scheme}}== |
||
Line 3,246: | Line 3,246: | ||
{{works with|Guile|2.0.13}} |
{{works with|Guile|2.0.13}} |
||
< |
<syntaxhighlight lang="scheme">(define short-date |
||
(lambda (lt) |
(lambda (lt) |
||
(strftime "%Y-%m-%d" (localtime lt)))) |
(strftime "%Y-%m-%d" (localtime lt)))) |
||
Line 3,263: | Line 3,263: | ||
(display (long-date dt))(newline)))) |
(display (long-date dt))(newline)))) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Seed7}}== |
=={{header|Seed7}}== |
||
< |
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i"; |
||
include "time.s7i"; |
include "time.s7i"; |
||
Line 3,279: | Line 3,279: | ||
writeln(strDate(now)); |
writeln(strDate(now)); |
||
writeln(days[dayOfWeek(now)] <& ", " <& months[now.month] <& " " <& now.day <& ", " <& now.year); |
writeln(days[dayOfWeek(now)] <& ", " <& months[now.month] <& " " <& now.day <& ", " <& now.year); |
||
end func;</ |
end func;</syntaxhighlight> |
||
=={{header|SenseTalk}}== |
=={{header|SenseTalk}}== |
||
< |
<syntaxhighlight lang="sensetalk"> |
||
put formattedTime( "[year]-[month]-[day]", the date) |
put formattedTime( "[year]-[month]-[day]", the date) |
||
put formattedTime( "[weekday], [month name] [day], [year]", the date) |
put formattedTime( "[weekday], [month name] [day], [year]", the date) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre>2019-12-18 |
<pre>2019-12-18 |
||
Line 3,292: | Line 3,292: | ||
=={{header|Shiny}}== |
=={{header|Shiny}}== |
||
< |
<syntaxhighlight lang="shiny">say time.format 'Y-m-d' time.now |
||
say time.format 'l, F j, Y' time.now</ |
say time.format 'l, F j, Y' time.now</syntaxhighlight> |
||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
< |
<syntaxhighlight lang="ruby">var time = Time.local; |
||
say time.ctime; |
say time.ctime; |
||
say time.strftime("%Y-%m-%d"); |
say time.strftime("%Y-%m-%d"); |
||
say time.strftime("%A, %B %d, %Y");</ |
say time.strftime("%A, %B %d, %Y");</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 3,310: | Line 3,310: | ||
In Smalltalk, one sends a <tt>printFormat</tt> message to a Date object with year, month, and day. For other date strings, one must construct the date string from the parts of a Date object. Of course, you'd probably want to make a method for doing so. |
In Smalltalk, one sends a <tt>printFormat</tt> message to a Date object with year, month, and day. For other date strings, one must construct the date string from the parts of a Date object. Of course, you'd probably want to make a method for doing so. |
||
< |
<syntaxhighlight lang="smalltalk">| d | |
||
d := Date today. |
d := Date today. |
||
d printFormat: #(3 2 1 $- 1 1 2). |
d printFormat: #(3 2 1 $- 1 1 2). |
||
(d weekday asString), ', ', (d monthName), ' ', (d dayOfMonth asString), ', ', (d year asString)</ |
(d weekday asString), ', ', (d monthName), ' ', (d dayOfMonth asString), ', ', (d year asString)</syntaxhighlight> |
||
{{works with|Smalltalk/X}} |
{{works with|Smalltalk/X}} |
||
< |
<syntaxhighlight lang="smalltalk">d := Date today. |
||
d printOn:Stdout format:'%y-%m-%d'. Stdout cr. |
d printOn:Stdout format:'%y-%m-%d'. Stdout cr. |
||
d printOn:Stdout format:'%(DayName), %(MonthName) %d, %y' language:#en. Stdout cr. |
d printOn:Stdout format:'%(DayName), %(MonthName) %d, %y' language:#en. Stdout cr. |
||
d printOn:Stdout format:'%(DayName), %(MonthName) %d, %y' language:#de. Stdout cr. |
d printOn:Stdout format:'%(DayName), %(MonthName) %d, %y' language:#de. Stdout cr. |
||
d printOn:Stdout format:'%(DayName), %(MonthName) %d, %y' language:#fr. Stdout cr.</ |
d printOn:Stdout format:'%(DayName), %(MonthName) %d, %y' language:#fr. Stdout cr.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>2020-12-17 |
<pre>2020-12-17 |
||
Line 3,328: | Line 3,328: | ||
=={{header|SQL}}== |
=={{header|SQL}}== |
||
{{works with|Oracle}} |
{{works with|Oracle}} |
||
< |
<syntaxhighlight lang="sql"> |
||
select to_char(sysdate,'YYYY-MM-DD') date_fmt_1 from dual; |
select to_char(sysdate,'YYYY-MM-DD') date_fmt_1 from dual; |
||
select to_char(sysdate,'fmDay, Month DD, YYYY') date_fmt_2 from dual; |
select to_char(sysdate,'fmDay, Month DD, YYYY') date_fmt_2 from dual; |
||
</syntaxhighlight> |
|||
</lang> |
|||
<pre> |
<pre> |
||
Line 3,349: | Line 3,349: | ||
Formatting rules: http://www.standardml.org/Basis/date.html#SIG:DATE.fmt:VAL |
Formatting rules: http://www.standardml.org/Basis/date.html#SIG:DATE.fmt:VAL |
||
< |
<syntaxhighlight lang="sml">print (Date.fmt "%Y-%m-%d" (Date.fromTimeLocal (Time.now ())) ^ "\n"); |
||
print (Date.fmt "%A, %B %d, %Y" (Date.fromTimeLocal (Time.now ())) ^ "\n");</ |
print (Date.fmt "%A, %B %d, %Y" (Date.fromTimeLocal (Time.now ())) ^ "\n");</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 3,361: | Line 3,361: | ||
Stata has many ways to format dates, see [https://www.stata.com/help.cgi?Datetime_display_formats Datetime display formats] in the documentation. |
Stata has many ways to format dates, see [https://www.stata.com/help.cgi?Datetime_display_formats Datetime display formats] in the documentation. |
||
< |
<syntaxhighlight lang="stata">display %tdCCYY-NN-DD td($S_DATE) |
||
display %tdDayname,_Month_dd,_CCYY td($S_DATE)</ |
display %tdDayname,_Month_dd,_CCYY td($S_DATE)</syntaxhighlight> |
||
=={{header|Suneido}}== |
=={{header|Suneido}}== |
||
< |
<syntaxhighlight lang="suneido">Date().Format('yyyy-MM-dd') --> "2010-03-16" |
||
Date().LongDate() --> "Tuesday, March 16, 2010" </ |
Date().LongDate() --> "Tuesday, March 16, 2010" </syntaxhighlight> |
||
=={{header|Swift}}== |
=={{header|Swift}}== |
||
< |
<syntaxhighlight lang="swift">import Foundation |
||
extension String { |
extension String { |
||
func toStandardDateWithDateFormat(format: String) -> String { |
func toStandardDateWithDateFormat(format: String) -> String { |
||
Line 3,379: | Line 3,379: | ||
} |
} |
||
let date = "2015-08-28".toStandardDateWithDateFormat("yyyy-MM-dd")</ |
let date = "2015-08-28".toStandardDateWithDateFormat("yyyy-MM-dd")</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 3,387: | Line 3,387: | ||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
< |
<syntaxhighlight lang="tcl">set now [clock seconds] |
||
puts [clock format $now -format "%Y-%m-%d"] |
puts [clock format $now -format "%Y-%m-%d"] |
||
puts [clock format $now -format "%A, %B %d, %Y"]</ |
puts [clock format $now -format "%A, %B %d, %Y"]</syntaxhighlight> |
||
=={{header|Terraform}}== |
=={{header|Terraform}}== |
||
< |
<syntaxhighlight lang="terraform">locals { |
||
today = timestamp() |
today = timestamp() |
||
} |
} |
||
Line 3,402: | Line 3,402: | ||
output "us-long" { |
output "us-long" { |
||
value = formatdate("EEEE, MMMM D, YYYY", local.today) |
value = formatdate("EEEE, MMMM D, YYYY", local.today) |
||
}</ |
}</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
Line 3,413: | Line 3,413: | ||
=={{header|TUSCRIPT}}== |
=={{header|TUSCRIPT}}== |
||
< |
<syntaxhighlight lang="tuscript"> |
||
$$ MODE TUSCRIPT |
$$ MODE TUSCRIPT |
||
SET dayofweek = DATE (today,day,month,year,number) |
SET dayofweek = DATE (today,day,month,year,number) |
||
Line 3,441: | Line 3,441: | ||
PRINT format1 |
PRINT format1 |
||
PRINT format2 |
PRINT format2 |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 3,449: | Line 3,449: | ||
=={{header|UNIX Shell}}== |
=={{header|UNIX Shell}}== |
||
< |
<syntaxhighlight lang="bash">date +"%Y-%m-%d" |
||
date +"%A, %B %d, %Y"</ |
date +"%A, %B %d, %Y"</syntaxhighlight> |
||
On a new enough system <code>%F</code> is equivalent to <code>%Y-%m-%d</code> |
On a new enough system <code>%F</code> is equivalent to <code>%Y-%m-%d</code> |
||
< |
<syntaxhighlight lang="bash">date +"%F"</syntaxhighlight> |
||
<!-- ENHANCE-ME: what is new enough for %F ? For example it doesn't appear in these bits of POSIX, |
<!-- ENHANCE-ME: what is new enough for %F ? For example it doesn't appear in these bits of POSIX, |
||
Line 3,463: | Line 3,463: | ||
{{works with|Cygnus/X Ursa}} |
{{works with|Cygnus/X Ursa}} |
||
Cygnus/X Ursa can import and call Java classes. |
Cygnus/X Ursa can import and call Java classes. |
||
< |
<syntaxhighlight lang="ursa">cygnus/x ursa v0.78 (default, release 0) |
||
[Oracle Corporation JVM 1.8.0_51 on Mac OS X 10.10.5 x86_64] |
[Oracle Corporation JVM 1.8.0_51 on Mac OS X 10.10.5 x86_64] |
||
> import "java.util.Date" |
> import "java.util.Date" |
||
Line 3,475: | Line 3,475: | ||
> out (sdf.format d) endl console |
> out (sdf.format d) endl console |
||
Saturday, July 23, 2016 |
Saturday, July 23, 2016 |
||
> _</ |
> _</syntaxhighlight> |
||
=={{header|Ursala}}== |
=={{header|Ursala}}== |
||
The method is to transform a date in standard format returned by the library function, now. |
The method is to transform a date in standard format returned by the library function, now. |
||
< |
<syntaxhighlight lang="ursala">#import std |
||
#import cli |
#import cli |
||
Line 3,495: | Line 3,495: | ||
#show+ |
#show+ |
||
main = <.text_form,numeric_form> now0</ |
main = <.text_form,numeric_form> now0</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Wednesday, June 24, 2009 |
<pre>Wednesday, June 24, 2009 |
||
Line 3,502: | Line 3,502: | ||
=={{header|VB-DOS|PDS 7.1 BASIC}}== |
=={{header|VB-DOS|PDS 7.1 BASIC}}== |
||
{{works with|Visual Basic for DOS and PDS 7.1}} |
{{works with|Visual Basic for DOS and PDS 7.1}} |
||
<syntaxhighlight lang="vb"> |
|||
<lang vb> |
|||
OPTION EXPLICIT |
OPTION EXPLICIT |
||
Line 3,541: | Line 3,541: | ||
END |
END |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|VBA}}== |
=={{header|VBA}}== |
||
< |
<syntaxhighlight lang="vba">Function DateFormats() |
||
Debug.Print Format(Date, "yyyy-mm-dd") |
Debug.Print Format(Date, "yyyy-mm-dd") |
||
Debug.Print Format(Date, "dddd, mmmm dd yyyy") |
Debug.Print Format(Date, "dddd, mmmm dd yyyy") |
||
End Function</ |
End Function</syntaxhighlight> |
||
=={{header|VBScript}}== |
=={{header|VBScript}}== |
||
<syntaxhighlight lang="vb"> |
|||
<lang vb> |
|||
'YYYY-MM-DD format |
'YYYY-MM-DD format |
||
WScript.StdOut.WriteLine Year(Date) & "-" & Right("0" & Month(Date),2) & "-" & Right("0" & Day(Date),2) |
WScript.StdOut.WriteLine Year(Date) & "-" & Right("0" & Month(Date),2) & "-" & Right("0" & Day(Date),2) |
||
Line 3,557: | Line 3,557: | ||
'Weekday_Name, Month_Name DD, YYYY format |
'Weekday_Name, Month_Name DD, YYYY format |
||
WScript.StdOut.WriteLine FormatDateTime(Now,1) |
WScript.StdOut.WriteLine FormatDateTime(Now,1) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{Out}} |
{{Out}} |
||
Line 3,568: | Line 3,568: | ||
Display current date in format "2007-11-10": |
Display current date in format "2007-11-10": |
||
< |
<syntaxhighlight lang="vedit">Date(REVERSE+NOMSG+VALUE, '-')</syntaxhighlight> |
||
Display current date in format "Sunday, November 10, 2007" (Requires VEDIT 6.2): |
Display current date in format "Sunday, November 10, 2007" (Requires VEDIT 6.2): |
||
< |
<syntaxhighlight lang="vedit">// Get todays date into #1, #2, #3 and #7 |
||
#1 = Date_Day |
#1 = Date_Day |
||
#2 = Date_Month |
#2 = Date_Month |
||
Line 3,601: | Line 3,601: | ||
// Display the date string |
// Display the date string |
||
RT(1) M(", ") RT(2) M(" ") NT(#1, LEFT+NOCR) M(",") NT(#3)</ |
RT(1) M(", ") RT(2) M(" ") NT(#1, LEFT+NOCR) M(",") NT(#3)</syntaxhighlight> |
||
To insert the date string into edit buffer instead of displaying it, replace the last line with this: |
To insert the date string into edit buffer instead of displaying it, replace the last line with this: |
||
< |
<syntaxhighlight lang="vedit">RI(1) IT(", ") RI(2) IT(" ") NI(#1, LEFT+NOCR) IT(",") NI(#3)</syntaxhighlight> |
||
=={{header|Vlang}}== |
=={{header|Vlang}}== |
||
< |
<syntaxhighlight lang="vlang">import time |
||
fn main() { |
fn main() { |
||
println(time.now().custom_format("YYYY-MM-DD")) |
println(time.now().custom_format("YYYY-MM-DD")) |
||
println(time.now().custom_format("dddd, MMMM D, YYYY")) |
println(time.now().custom_format("dddd, MMMM D, YYYY")) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 3,624: | Line 3,624: | ||
{{libheader|Wren-date}} |
{{libheader|Wren-date}} |
||
Unless it is embedded in a host application, Wren currently has no direct way to obtain the current date. We therefore assume this is passed in by the user as a command line parameter. |
Unless it is embedded in a host application, Wren currently has no direct way to obtain the current date. We therefore assume this is passed in by the user as a command line parameter. |
||
< |
<syntaxhighlight lang="ecmascript">import "os" for Process |
||
import "/date" for Date |
import "/date" for Date |
||
Line 3,633: | Line 3,633: | ||
var current = Date.parse(args[0]) |
var current = Date.parse(args[0]) |
||
System.print(current.format(Date.isoDate)) |
System.print(current.format(Date.isoDate)) |
||
System.print(current.format("dddd|, |mmmm| |d|, |yyyy"))</ |
System.print(current.format("dddd|, |mmmm| |d|, |yyyy"))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 3,643: | Line 3,643: | ||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
< |
<syntaxhighlight lang="xpl0">include c:\cxpl\codes; |
||
int CpuReg, Year, Month, Day, DName, MName, WDay; |
int CpuReg, Year, Month, Day, DName, MName, WDay; |
||
[CpuReg:= GetReg; \access CPU registers |
[CpuReg:= GetReg; \access CPU registers |
||
Line 3,661: | Line 3,661: | ||
Text(0, DName(WDay)); Text(0, ", "); Text(0, MName(Month)); Text(0, " "); |
Text(0, DName(WDay)); Text(0, ", "); Text(0, MName(Month)); Text(0, " "); |
||
IntOut(0, Day); Text(0, ", "); IntOut(0, Year); CrLf(0); |
IntOut(0, Day); Text(0, ", "); IntOut(0, Year); CrLf(0); |
||
]</ |
]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 3,670: | Line 3,670: | ||
=={{header|Yabasic}}== |
=={{header|Yabasic}}== |
||
< |
<syntaxhighlight lang="yabasic">dim n$(1) |
||
n = token(date$, n$(), "-") |
n = token(date$, n$(), "-") |
||
Line 3,697: | Line 3,697: | ||
return month$(int(n/3) + 1) |
return month$(int(n/3) + 1) |
||
end sub</ |
end sub</syntaxhighlight> |
||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
< |
<syntaxhighlight lang="zkl">"%d-%02d-%02d".fmt(Time.Clock.localTime.xplode()).println() |
||
//--> "2014-02-28" (ISO format)</ |
//--> "2014-02-28" (ISO format)</syntaxhighlight> |
||
Not quite but close. Even though localTime returns a 7 tuple (and xplode pushes all 7 as call args), fmt only eats what it needs. |
Not quite but close. Even though localTime returns a 7 tuple (and xplode pushes all 7 as call args), fmt only eats what it needs. |
||
< |
<syntaxhighlight lang="zkl">Time.Date.prettyDay(Time.Clock.localTime.xplode()) |
||
//--> "Friday, the 28th of February 2014"</ |
//--> "Friday, the 28th of February 2014"</syntaxhighlight> |
||
< |
<syntaxhighlight lang="zkl">y,m,d:=Time.Clock.localTime; D:=Time.Date; |
||
"%s, %s %d, %d".fmt(D.dayName(D.weekDay(y,m,d)), |
"%s, %s %d, %d".fmt(D.dayName(D.weekDay(y,m,d)), |
||
D.monthName(m), d,y) |
D.monthName(m), d,y) |
||
//-->"Friday, February 28, 2014"</ |
//-->"Friday, February 28, 2014"</syntaxhighlight> |
||
=={{header|zonnon}}== |
=={{header|zonnon}}== |
||
< |
<syntaxhighlight lang="zonnon"> |
||
module Main; |
module Main; |
||
import System; |
import System; |
||
Line 3,722: | Line 3,722: | ||
System.Console.WriteLine("{0}, {1}",now.DayOfWeek,now.ToString("MMMM dd, yyyy")); |
System.Console.WriteLine("{0}, {1}",now.DayOfWeek,now.ToString("MMMM dd, yyyy")); |
||
end Main. |
end Main. |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{Out}} |
{{Out}} |
||
<pre> |
<pre> |