Date format: Difference between revisions
Content deleted Content added
→Nu: add |
|||
(31 intermediate revisions by 19 users not shown) | |||
Line 9:
=={{header|11l}}==
<
print(Time().strftime(‘%A, %B %e, %Y’))</
=={{header|68000 Assembly}}==
Line 17:
<
MOVE.B #'2',D0 ;a character in single or double quotes refers to its ascii equivalent.
Line 124:
MOVE.B D1,D0 ;store in low word
popWord D1
rts</
Output can be seen [https://ibb.co/52Ks0yf here,] but is also reproduced below:
Line 133:
=={{header|8th}}==
<
d:new
"%Y-%M-%D" over d:format . cr
"%W, %N %D, %Y" over d:format . cr
bye
</syntaxhighlight>
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program dateFormat64.s */
Line 463:
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
=={{header|ABAP}}==
<syntaxhighlight lang="abap">
report zdate.
data: lv_month type string,
Line 487:
concatenate sy-datum(4) '-' sy-datum+4(2) '-' sy-datum+6(2) into lv_date.
write / lv_date.
</syntaxhighlight>
=={{header|Action!}}==
<
TYPE Date=[
Line 560:
PrintDateShort(d) PutE()
PrintDateLong(d) PutE()
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Date_format.png Screenshot from Atari 8-bit computer]
Line 569:
=={{header|Ada}}==
<
with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
with Ada.Text_IO; use Ada.Text_IO;
Line 612:
& Year_Number'Image (Ada.Calendar.Year (Today))
);
end Date_Format;</
{{out}}
Line 625:
Note: the '''format''' can be used for both printing ''and'' reading date data.
<
STRUCT ( INT sec, min, hour, mday, mon, year, wday, yday, isdst) tm = (6,5,4,3,2,1,7,~,8);
Line 647:
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$))</
{{out}}
<pre>
Line 656:
=={{header|Apex}}==
<
Datetime dtNow = datetime.now();
String strDt1 = dtNow.format('yyyy-MM-dd');
Line 662:
system.debug(strDt1); // "2007-11-10"
system.debug(strDt2); //"Sunday, November 10, 2007"
</syntaxhighlight>
{{out}}
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.
<
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)
return (shortFormat & linefeed & longFormat)</
{{output}}
<
Wednesday, October 28, 2020"</
===Hack alternative===
Line 702:
<
set shortdate to text 1 thru 10 of (it as «class isot» as string)
set longdate to the contents of [its weekday, ", ", ¬
Line 709:
log the shortdate
log the longdate</
{{output}}
Line 718:
Or, emphasising productivity and functional composition:
<
on iso8601Short(dte)
text 1 thru 10 of iso8601Local(dte)
Line 788:
set my text item delimiters to dlm
s
end unlines</
{{Out}}
<pre>2020-09-11
Line 795:
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
/* ARM assembly Raspberry PI */
/* program dateFormat.s */
Line 1,143:
/***************************************************/
.include "../affichage.inc"
</syntaxhighlight>
{{Output}}
<pre>
Line 1,158:
=={{header|Arturo}}==
<
print to :string.format: "YYYY-MM-dd" currentTime
print to :string.format: "dddd, MMMM dd, YYYY" currentTime</
{{out}}
Line 1,169:
=={{header|AutoHotkey}}==
<
FormatTime, Date2, , LongDate ; "Sunday, November 10, 2007"
MsgBox %Date1% `n %Date2%</
=={{header|AutoIt}}==
This solution uses the locale settings for names of days and months.
<syntaxhighlight lang="autoit">
#include <Date.au3>
Line 1,207:
Return $ret[3]
EndFunc
</syntaxhighlight>
{{out}}
<pre>
Line 1,217:
=={{header|AWK}}==
{{works with|Gawk}}
<
2009-05-15
Friday, May 15, 2009</
=={{header|BaCon}}==
<
n = NOW
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"</
{{out}}
Line 1,234:
=={{header|BASIC}}==
{{works with|FreeBASIC}}
<
DIM today As Double = Now()
PRINT Format(today, "yyyy-mm-dd")
PRINT Format(today, "dddd, mmmm d, yyyy")</
=={{header|Batch File}}==
<
@echo off
setlocal enabledelayedexpansion
Line 1,278:
echo %fulldayname%, %monthname% %day%, %year%
pause>nul
</syntaxhighlight>
{{out}}
<pre>
Line 1,286:
=={{header|BBC BASIC}}==
<
months$ = "January February March April May June " + \
\ "July August September October November December"
Line 1,303:
DEF FNrtrim(A$)
WHILE RIGHT$(A$) = " " A$ = LEFT$(A$) : ENDWHILE
= A$</
=={{header|Beads}}==
Line 1,333:
// [iso time] = [hour]:[minute]:[second], e.g. 18:06:05
</pre>
<
calc main_init
log time_to_str('[iso date]')
log time_to_str('[sunday], [january] [day2], [year]')</
{{out}}
Line 1,346:
=={{header|C}}==
<
#include <stdio.h>
#include <time.h>
Line 1,368:
(void) printf("%s\n", buf);
return EXIT_SUCCESS;
}</
{{out}}
<pre>
Line 1,376:
=={{header|C sharp|C#}}==
<
namespace RosettaCode.DateFormat
Line 1,389:
}
}
}</
=={{header|C++}}==
<
// and "Sunday, November 10, 2007".
Line 1,455:
std::cout << d.getTextDate() << std::endl;
return 0;
}</
{{out}}
<pre>
Line 1,463:
=={{header|Clojure}}==
<
f1 (java.text.SimpleDateFormat. "yyyy-MM-dd")
f2 (java.text.SimpleDateFormat. "EEEE, MMMM dd, yyyy")]
(println (.format f1 now))
(println (.format f2 now)))</
{{out}}
Line 1,475:
=={{header|COBOL}}==
{{works with|OpenCOBOL}}
<
PROGRAM-ID. Date-Format.
Line 1,538:
GOBACK
.</
=={{header|CoffeeScript}}==
=== 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).
<
date = new Date
Line 1,557:
day: 'numeric'
year: 'numeric'
</syntaxhighlight>
=== Portable version ===
<
# JS does not have extensive formatting support out of the box. This code shows
# how you could create a date formatter object.
Line 1,587:
console.log formatter.brief(date)
console.log formatter.verbose(date)
</syntaxhighlight>
{{out}}
<pre>
Line 1,596:
=={{header|ColdFusion}}==
<
#dateFormat(Now(), "YYYY-MM-DD")#<br />
#dateFormat(Now(), "DDDD, MMMM DD, YYYY")#
</cfoutput></
=={{header|Common Lisp}}==
<
#("Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday"))
(defconstant *month-names*
Line 1,611:
(format t "~4d-~2,'0d-~2,'0d~%" year month date)
(format t "~a, ~a ~d, ~4d~%"
(aref *day-names* day) (aref *month-names* month) date year))</
With the local-time library:
<
(local-time:format-timestring nil (local-time:now) :format '(:year "-" (:month 2) "-" (:day 2)))
;; => "2019-11-13"
(local-time:format-timestring nil (local-time:now) :format '(:long-weekday ", " :long-month #\space (:day 2) ", " :year))
;; => "Wednesday, November 13, 2019"
</syntaxhighlight>
=={{header|Component Pascal}}==
BlackBox Component Builder
<
MODULE DateFormat;
IMPORT StdLog, Dates;
Line 1,646:
END Do;
END DateFormat.
</syntaxhighlight>
Execute: ^Q DateFormat.Do<br/>
{{out}}
Line 1,660:
=={{header|Crystal}}==
{{works with|Crystal|0.33}}
<
time = Time.local
puts time.to_s("%Y-%m-%d")
puts time.to_s("%A, %B %d, %Y")
</syntaxhighlight>
=={{header|D}}==
{{works with|D|DMD 1.026}}
{{libheader|Tango}}
<
import tango.time.Time ;
Line 1,686:
d = g.toTime(2008, 2, 1, 0, 0, 0, 0, g.AD_ERA) ;
Stdout.format("{:dddd, MMMM d, yyy}", d).newline ;
}</
{{out}}
<pre>2007-11-10
Line 1,693:
=={{header|Delphi}}==
<
{{out}}
<pre>
Line 1,700:
Redirecting to
</pre>
=={{header|Diego}}==
<syntaxhighlight lang="diego">me_lang(en)_cal(gregorian);
me_msg()_now()_format(yyyy-mm-dd);
me_msg()_now()_format(eeee, mmmm dd, yyyy);</syntaxhighlight>
=={{header|EasyLang}}==
<syntaxhighlight lang=text>
func wkday year month day .
adj = (14 - month) div 12
mm = month + 12 * adj - 2
yy = year - adj
r = day + (13 * mm - 1) div 5 + yy + yy div 4 - yy div 100 + yy div 400
return r mod 7 + 1
.
month$[] = [ "January" "February" "March" "April" "May" "June" "July" "August" "September" "October" "November" "December" ]
wday$[] = [ "Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" ]
#
s$ = timestr systime
y$ = substr s$ 1 4
y = number y$
m$ = substr s$ 6 2
m = number m$
d$ = substr s$ 9 2
d = number d$
#
print y$ & "-" & m$ & "-" & d$
print wday$[wkday y m d] & ", " & month$[m] & " " & d & ", " & y
</syntaxhighlight>
{{out}}
<pre>
2024-07-22
Monday, July 22, 2024
</pre>
=={{header|Ed}}==
Using <tt>date</tt> is cheating, but ed has no built-in date fetching/formatting. Most other languages use strftime, which is basically the same thing, anyway.
<syntaxhighlight lang="sed">
H
!date +"\%Y-\%m-\%d"
!date +"\%A, \%B \%d, \%Y"
Q
</syntaxhighlight>
=={{header|EGL}}==
<syntaxhighlight lang="egl">
// 2012-09-26
SysLib.writeStdout(StrLib.formatDate(DateTimeLib.currentDate(), "yyyy-MM-dd"));
Line 1,708 ⟶ 1,753:
SysLib.setLocale("en", "US");
SysLib.writeStdout(StrLib.formatDate(DateTimeLib.currentDate(), "EEEE, MMMM dd, yyyy"));
</syntaxhighlight>
{{out}}
<pre>
Line 1,718 ⟶ 1,763:
{{trans|Erlang}}
{{works with|Elixir|1.4}}
<
def iso_date, do: Date.utc_today |> Date.to_iso8601
Line 1,740 ⟶ 1,785:
IO.puts Date_format.long_date
IO.puts Date_format.iso_date(2007,11,10)
IO.puts Date_format.long_date(2007,11,10)</
{{out}}
Line 1,751 ⟶ 1,796:
=={{header|Emacs Lisp}}==
<
(format-time-string "%F") ;; new in Emacs 24
;; => "2015-11-08"
(format-time-string "%A, %B %e, %Y")
;; => "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.
Line 1,763 ⟶ 1,807:
=={{header|Erlang}}==
<
-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]).
Line 1,786 ⟶ 1,830:
MonthName = element(Month, Months),
append([WeekdayName, ", ", MonthName, " ", integer_to_list(Day), ", ",
integer_to_list(Year)]).</
=={{header|Euphoria}}==
<
constant months = {"January","February","March","April","May","June",
"July","August","September","October","November","December"}
Line 1,799 ⟶ 1,843:
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]})</
=={{header|F_Sharp|F#}}==
"F# Interactive" session:
<
> Console.WriteLine( DateTime.Now.ToString("yyyy-MM-dd") );;
2010-08-13
> Console.WriteLine( "{0:D}", DateTime.Now );;
Friday, August 13, 2010</
=={{header|Factor}}==
<
now "%Y-%m-%d" strftime print
now "%A, %B %d, %Y" strftime print</
=={{header|Fantom}}==
Line 1,819 ⟶ 1,863:
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
<
fansh> Date.today.toLocale("YYYY-MM-DD")
2011-02-24
fansh> Date.today.toLocale("WWWW, MMMM DD, YYYY")
Thursday, February 24, 2011
</syntaxhighlight>
=={{header|Forth}}==
<
[char] - emit
dup 10 < if [char] 0 emit then ;
Line 1,881 ⟶ 1,925:
3dup weekday weekdays type ." , "
>R 1- months type space 1 u.r ." , " R> .
drop drop drop ;</
=== Version 2: Meta Language ===
Forth is less of a language and more of an extensible toolkit of simple routines. This version attempts to demonstrate using the simple routines to extend Forth. Then using the language extensions and the power of concatenative language to solve the problem. This solution could create numerous date formats as one line definitions now that we have our "date" words defined. Typically these extensions would be saved as a library file.
<
\ utility words
Line 1,946 ⟶ 1,990:
\ Rosetta Date Format 2
: LONG.DATE ( d m y -- )
3DUP CDAY DOW ]DAY$. ',' -ROT ]MONTH$. SPACE ##. ',' ####. ;</
Test at the Forth Console
<
ok
5 7 2018 LONG.DATE Thursday, July 05, 2018 ok
</syntaxhighlight>
=={{header|Fortran}}==
{{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
<
IMPLICIT NONE
Line 2,026 ⟶ 2,071:
END FUNCTION Day_of_week
END PROGRAM DATE</
{{out}}
2008-12-14
Line 2,032 ⟶ 2,077:
=={{header|FreeBASIC}}==
<
#Include "vbcompat.bi"
Line 2,041 ⟶ 2,086:
Print
Print "Press any key to quit the program"
Sleep</
{{out}}
Line 2,050 ⟶ 2,095:
=={{header|Free Pascal}}==
<syntaxhighlight lang="pascal">program Format_Date_Time;
uses
SysUtils;
begin
WriteLn(FormatDateTime('yyyy-mm-dd', Now) +#13#10+ FormatDateTime('dddd, mmmm dd, yyyy', Now));
end.
</syntaxhighlight>
{{out}}
<pre>
Line 2,058 ⟶ 2,109:
=={{header|Frink}}==
<
println[now[] -> ### yyyy-MM-dd ###]
println[now[] -> ### EEEE, MMMM d, yyyy ###]
</syntaxhighlight>
=={{header|FunL}}==
<
println( format('%1$tA, %1$tB %1$td, %1$tY', $date) )</
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">window 1
print date(@"yyyy-MM-dd")
print date(@"EEEE, MMMM dd, yyyy")
HandleEvents</syntaxhighlight>
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/ You can run this code. Copy the code, click this link, paste it in and press 'Run !']'''
<
Print Format(Now, "yyyy - mm - dd")
Print Format(Now, "dddd, mmmm dd, yyyy")
End</
Output:
<pre>
Line 2,083 ⟶ 2,142:
=={{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
<
import "time"
Line 2,091 ⟶ 2,150:
fmt.Println(time.Now().Format("2006-01-02"))
fmt.Println(time.Now().Format("Monday, January 2, 2006"))
}</
{{out}}
<pre>
Line 2,100 ⟶ 2,159:
=={{header|Groovy}}==
Solution:
<
def longFormat = { date -> date.format("EEEE, MMMM dd, yyyy") }</
Test Program:
<
println isoFormat(now)
println longFormat(now)</
=={{header|Haskell}}==
<
(FormatTime, formatTime, defaultTimeLocale, utcToLocalTime,
getCurrentTimeZone, getCurrentTime)
Line 2,119 ⟶ 2,178:
main = do
t <- pure utcToLocalTime <*> getCurrentTimeZone <*> getCurrentTime
putStrLn $ unlines (formats <*> pure t)</
'''Sample output:'''
<pre>2017-06-05
Line 2,125 ⟶ 2,184:
=={{header|HicEst}}==
<
WRITE(Text=string, Format='UCCYY-MM-DD') 0 ! string: 2010-03-13
Line 2,137 ⟶ 2,196:
EDIT(Text=string, Right=' ', Mark1, Right=';', Right=3, Mark2, Delete, Insert=', '//cMonth, Right=';', RePLaceby=',')
END</
=={{header|Icon}} and {{header|Unicon}}==
<
write(map(&date,"/","-"))
write(&dateline ? tab(find(&date[1:5])+4))
end</
{{out}}
Line 2,151 ⟶ 2,210:
=={{header|J}}==
Short format using built in formatting:
<
2010-08-19</
Verb to show custom format:
<
days=:;:'Sunday Monday Tuesday Wednesday Thursday Friday Saturday'
fmtDate=: [:((days ;@{~ weekday),', ',ms0) 3 {.]
fmtDate 6!:0 ''
Thursday, August 19, 2010</
=={{header|Java}}==
<
public static void main(String[] args) {
long millis = System.currentTimeMillis();
System.out.printf("%tF%n", millis);
System.out.printf("%tA, %1$tB %1$td, %1$tY%n", millis);
}
</syntaxhighlight>
<pre>
2023-05-10
Wednesday, May 10, 2023
</pre>
<br />
An alternate demonstration
<syntaxhighlight lang="java">
import java.util.Calendar;
import java.util.GregorianCalendar;
Line 2,182 ⟶ 2,254:
}
}
</syntaxhighlight>
Better: use a library, see http://sourceforge.net/apps/mediawiki/threeten/index.php?title=ThreeTen
===Java 8 Date Time API===
<
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
Line 2,200 ⟶ 2,272:
}
}
</syntaxhighlight>
===Java Util Date API===
<
import java.text.SimpleDateFormat;
import java.util.Date;
Line 2,215 ⟶ 2,287:
}
}
</syntaxhighlight>
=={{header|JavaScript}}==
JavaScript does not have any built-in <code>strftime</code>-type functionality.
<
weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
Line 2,225 ⟶ 2,297:
fmt2 = weekdays[now.getDay()] + ', ' + months[now.getMonth()] + ' ' + now.getDate() + ', ' + now.getFullYear();
console.log(fmt1);
console.log(fmt2);</
<pre>2010-1-12
Tuesday, January 12, 2010</pre>
=={{header|Joy}}==
<syntaxhighlight lang="joy">
DEFINE weekdays == [
months == [
time localtime [
[i] map [putchars] step '\n putch pop.
time localtime [
[", "] [0 at 'd 4 4 format]
</syntaxhighlight>
=={{header|jq}}==
{{works with|jq|with strftime}}
<
"2015-07-02"
"Thursday, July 02, 2015"</
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,253 ⟶ 2,325:
{{works with|Julia|0.6}}
<
println("Today's date is:")
println("\t$ts")
println("\t", Dates.format(ts, "E, U dd, yyyy"))</
{{out}}
Line 2,265 ⟶ 2,337:
=={{header|Kotlin}}==
<
import java.util.GregorianCalendar
Line 2,273 ⟶ 2,345:
println("%tF".format(now))
println("%tA, %1\$tB %1\$te, %1\$tY".format(now))
}</
{{out}}
Line 2,282 ⟶ 2,354:
=={{header|langur}}==
<syntaxhighlight lang="langur">writeln string(dt//, "2006-01-02")
writeln string(dt//, "Monday, January 2, 2006")
</syntaxhighlight>
<syntaxhighlight lang="langur">
writeln "{{dt//:dt(2006-01-02)}}"
writeln
</syntaxhighlight>
{{out}}
<pre>2020-03-26
Thursday, March 26, 2020</pre>
=={{header|Lasso}}==
<syntaxhighlight lang="lasso">
date('11/10/2007')->format('%Q') // 2007-11-10
date('11/10/2007')->format('EEEE, MMMM d, YYYY') //Saturday, November 10, 2007
</syntaxhighlight>
=={{header|Liberty BASIC}}==
<
d$=date$("yyyy/mm/dd")
print word$(d$,1,"/")+"-"+word$(d$,2,"/")+"-"+word$(d$,3,"/")
Line 2,346 ⟶ 2,397:
monthLong$="January February March April May June July August September October November December"
print word$(weekDay$,theDay+1);", ";word$(monthLong$,month);" ";day;", ";year</
=={{header|LiveCode}}==
<syntaxhighlight lang="livecode">on mouseUp pButtonNumber
put the date into tDate
convert tDate to dateItems
put item 1 of tDate & "-" & item 2 of tDate & "-" & item 3 of tDate & return into tMyFormattedDate
put tMyFormattedDate & the long date
end mouseUp </syntaxhighlight>
=={{header|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:
<
print first shell [date +%F]
print first shell [date +"%A, %B %d, %Y"]
</syntaxhighlight>
{{Out}}
<pre>2020-09-16
Line 2,360 ⟶ 2,420:
=={{header|Lua}}==
<
print( os.date( "%A, %B %d, %Y" ) )</
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
Print str$(today, "yyyy-mm-dd")
Print str$(today, "dddd, mmm, dd, yyyy")
</syntaxhighlight>
=={{header|Maple}}==
<syntaxhighlight lang="maple">
with(StringTools);
FormatTime("%Y-%m-%d")
FormatTime("%A,%B %d, %y")
</syntaxhighlight>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
DateString[{"DayName", ", ", "MonthName", " ", "Day", ", ", "Year"}]</
=={{header|MATLAB}} / {{header|Octave}}==
<
ans =
Line 2,392 ⟶ 2,452:
ans =
Friday, June 18, 2010</
=={{header|min}}==
{{works with|min|0.19.3}}
<
{{out}}
<pre>
2019-04-02
Tuesday, April 02, 2019
</pre>
=={{header|MiniScript}}==
<syntaxhighlight lang="miniscript">import "dateTime"
print dateTime.now("yyyy-MM-dd")
print dateTime.now("dddd, MMMM d, yyyy")</syntaxhighlight>
{{out}}
<pre>2023-12-28
Thursday, December 28, 2023
</pre>
=={{header|mIRC Scripting Language}}==
<
echo -ag $time(dddd $+ $chr(44) mmmm dd $+ $chr(44) yyyy)</
=={{header|MUMPS}}==
{{works with|MUMPS|Intersystems' Caché|(all versions)}}
Functions starting with 'Z' or '$Z' are implementation specific.
<
WRITE !,"Date format 3: ",$ZDATE($H,3)
WRITE !,"Or ",$ZDATE($H,12),", ",$ZDATE($H,9)
QUIT</
<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}}
<
;You can pass an integer, but the default is to use today's value
SET:$DATA(H)=0 H=$HOROLOG
Line 2,436 ⟶ 2,507:
WRITE !,$P(DN,",",DOW),", ",$P(MN,",",MO)," ",DA,", ",YR
KILL Y,YR,RD,MC,MO,DA,MN,DN,DOW
QUIT</
Demos:<pre>
USER>D DTM^ROSETTA
Line 2,453 ⟶ 2,524:
=={{header|Nanoquery}}==
<
d = new(Date)
println d.getYear() + "-" + d.getMonth() + "-" + d.getDay()
println d.getDayOfWeek() + ", " + d.getMonthName() + " " + d.getDay() + ", " + d.getYear()</
=={{header|Neko}}==
<syntaxhighlight lang="actionscript">/**
<doc>
<h2>Date format</h2>
Line 2,473 ⟶ 2,544:
var now = date_now()
$print(date_format(now, "%F"), "\n")
$print(date_format(now, "%A, %B %d, %Y"), "\n")</
{{out}}
<pre>prompt$ nekoc date-format.neko
Line 2,481 ⟶ 2,552:
=={{header|NetRexx}}==
<syntaxhighlight lang="netrexx">
import java.text.SimpleDateFormat
say SimpleDateFormat("yyyy-MM-dd").format(Date())
say SimpleDateFormat("EEEE, MMMM dd, yyyy").format(Date())
</syntaxhighlight>
{{out}}
<pre>2019-02-10
Line 2,491 ⟶ 2,562:
=={{header|NewLISP}}==
<
; url: http://rosettacode.org/wiki/Date_format
; author: oofoe 2012-02-01
Line 2,524 ⟶ 2,595:
(println "long: " (date (date-value) 0 "%A, %B %#d, %Y"))
(exit)</
{{out}}
Line 2,534 ⟶ 2,605:
=={{header|Nim}}==
<
var t = now()
echo(t.format("yyyy-MM-dd"))
echo(t.format("dddd',' MMMM d',' yyyy"))</
=={{header|Nu}}==
{{works with|Nushell|0.96.1}}
<syntaxhighlight lang="nu">let now = date now
['%F' '%A, %B %e, %Y'] | each {|fmt| $now | format date $fmt }</syntaxhighlight>
=={{header|Objeck}}==
<
use IO;
use Time;
Line 2,557 ⟶ 2,634:
}
}
</syntaxhighlight>
{{out}}
Line 2,566 ⟶ 2,643:
=={{header|Objective-C}}==
<
NSLog(@"%@", [[NSDate date] descriptionWithCalendarFormat:@"%Y-%m-%d" timeZone:nil locale:nil]);
NSLog(@"%@", [[NSDate date] descriptionWithCalendarFormat:@"%A, %B %d, %Y" timeZone:nil locale:nil]);</
{{works with|Mac OS X|10.4+}}
{{works with|iOS}}
<
NSDateFormatter *dateFormatter = [[NSDateFormat alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSLog(@"%@", [dateFormatter stringFromDate:[NSDate date]]);
[dateFormatter setDateFormat:@"EEEE, MMMM d, yyyy"];
NSLog(@"%@", [dateFormatter stringFromDate:[NSDate date]]);</
=={{header|OCaml}}==
<
# open Unix;;
Line 2,593 ⟶ 2,670:
# Printf.sprintf "%d-%02d-%02d" (1900 + gmt.tm_year) (1 + gmt.tm_mon) gmt.tm_mday ;;
- : string = "2008-08-29"</
<
"July"; "August"; "September"; "October"; "November"; "December" |]
Line 2,606 ⟶ 2,683:
gmt.tm_mday
(1900 + gmt.tm_year) ;;
- : string = "Friday, August 29, 2008"</
=={{header|ooRexx}}==
<
dats='20071123'
Say date('I',dats,'S')
Line 2,616 ⟶ 2,693:
dati=date('I')
Say dati
Say date('W',dati,'I')',' date('M',dati,'I') translate('ij, abcd',dati,'abcdefghij')</
{{out}}2007-11-23
Friday, November 23, 2007
Line 2,624 ⟶ 2,701:
=={{header|OxygenBasic}}==
<
extern lib "kernel32.dll"
Line 2,656 ⟶ 2,733:
print "" t.wYear "-" month "-" day
print WeekDay[t.wDayOfWeek+1 and 7 ] " " MonthName[t.wMonth and 31] " " t.wDay " " t.wYear
</syntaxhighlight>
=={{header|Oz}}==
Getting the current local date is easy, but we have to do the formatting manually.
<
WeekDays = unit(0:"Sunday" "Monday" "Tuesday" "Wednesday"
"Thursday" "Friday" "Saturday")
Line 2,685 ⟶ 2,762:
in
{System.showInfo {DateISO {OS.localTime}}}
{System.showInfo {DateLong {OS.localTime}}}</
=={{header|Pascal}}==
{{works with|Turbo Pascal|5.5}}
<
uses DOS;
Line 2,743 ⟶ 2,820:
mname := m2s(mo); dname := d2s(dow);
writeln(dname,', ',mname,' ',dy,', ',yr)
end.</
{{out}}
<pre>2010-07-30
Friday, July 30, 2010</pre>
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="delphi">
begin
var today := DateTime.Now;
Println(today.ToString('yyyy-MM-dd'));
Println($'{today:D}');
end.
</syntaxhighlight>
{{out}}
<pre>
2024-06-01
Saturday, June 1, 2024
</pre>
=={{header|Perl}}==
{{libheader|POSIX}}
<
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";</
{{out}} with locales '''C''':
Line 2,765 ⟶ 2,856:
Actual date:
<
print strftime('%Y-%m-%d', localtime), "\n";
print strftime('%A, %B %d, %Y', localtime), "\n";</
{{out}} with locales '''C''':
Line 2,776 ⟶ 2,867:
=={{header|Phix}}==
{{libheader|Phix/basics}}
<!--<
<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: #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>
<!--</
{{out}}
<pre>
Line 2,790 ⟶ 2,881:
=={{header|PHP}}==
Formatting rules: http://www.php.net/date
<
echo date('Y-m-d', time())."\n";
echo date('l, F j, Y', time())."\n";
?></
=={{header|PicoLisp}}==
<
(prinl (dat$ Date "-")) # 2010-02-19
(prinl # Friday, February 19, 2010
Line 2,805 ⟶ 2,896:
(caddr Lst)
", "
(car Lst) ) )</
=={{header|Pike}}==
<syntaxhighlight lang="pike">
object cal = Calendar.ISO.Day();
write( cal->format_ymd() +"\n" );
Line 2,817 ⟶ 2,908:
cal->year_no());
write( special +"\n" );
</syntaxhighlight>
{{Out}}
<pre>
Line 2,826 ⟶ 2,917:
=={{header|PL/I}}==
===Version 1===
<
declare day_of_week(7) character (9) varying initial(
'Sunday','Monday','Tuesday','Wednesday',
Line 2,840 ⟶ 2,931:
put edit(substr(today,1,3),' ',substr(today,4,2),', ',
substr(today,6,4))(A);
end;</
{{out}}
<pre>2013-11-02
Line 2,846 ⟶ 2,937:
===Version 2===
<
declare day_of_week(7) character(9) varying initial(
'Sunday','Monday','Tuesday','Wednesday',
Line 2,861 ⟶ 2,952:
put edit(month(substr(today,1,2)),' ',substr(today,3,2),', ',
substr(today,5,4))(A);
End;</
{{out}}
<pre>2013-11-02
Line 2,867 ⟶ 2,958:
=={{header|PowerShell}}==
<
"{0:dddd, MMMM d, yyyy}" -f (Get-Date)
# or
(Get-Date).ToString("yyyy-MM-dd")
(Get-Date).ToString("dddd, MMMM d, yyyy")</
''Note:'' The names of months and days follow the currently set locale but otherwise the format is unchanged.
Line 2,878 ⟶ 2,969:
{{works with|SWI-Prolog|6}}
<
display_date :-
get_time(Time),
Line 2,884 ⟶ 2,975:
format_time(atom(Long), '%A, %B %d, %Y', Time),
format('~w~n~w~n', [Short, Long]).
</syntaxhighlight>
=={{header|PureBasic}}==
{{works with|PureBasic|4.41}}
<
Declare.s MonthInText()
Declare.s DayInText()
Line 2,928 ⟶ 3,019:
EndSelect
ProcedureReturn m$
EndProcedure</
=={{header|Python}}==
Formatting rules: http://docs.python.org/lib/module-time.html (strftime)
<
today = datetime.date.today()
# The first requested format is a method of datetime objects:
Line 2,946 ⟶ 3,037:
# Since Python 3.6, f-strings allow the value to be inserted inline
f"The date is {d:%A, %B %d, %Y}"
</syntaxhighlight>
=={{header|R}}==
strftime is short for "string format time".
<
strftime(now, "%Y-%m-%d")
strftime(now, "%A, %B %d, %Y")</
=={{header|Racket}}==
Line 2,966 ⟶ 3,057:
See: http://srfi.schemers.org/srfi-19/srfi-19.html
<
(require srfi/19)
Line 2,978 ⟶ 3,069:
(displayln (date->string (current-date) "~A, ~B ~d, ~Y"))
;;; ~e is space padded day of month:
(displayln (date->string (current-date) "~A, ~B ~e, ~Y"))</
both ~d and ~e satisfy the format required, since the "10" part of that date is 2-digit
Line 2,989 ⟶ 3,080:
(formerly Perl 6)
{{libheader|DateTime::Format}}
<syntaxhighlight lang="raku"
my $dt = DateTime.now;
say strftime('%Y-%m-%d', $dt);
say strftime('%A, %B %d, %Y', $dt);</
The built-in Date and DateTime classes both offer support for the ISO format:
<syntaxhighlight lang="raku"
say $d.yyyy-mm-dd;</
They don't include the longer format specified in the task, but you can always roll your own formatter instead of importing the library:
<syntaxhighlight lang="raku"
August September October November December>;
my @days = <Monday Tuesday Wednesday Thursday Friday Saturday Sunday>;
Line 3,010 ⟶ 3,101:
say $d.yyyy-mm-dd; # still works
say $d; # uses our formatter sub</
=={{header|Raven}}==
<syntaxhighlight lang
Short form:
<
Long form:
<
=={{header|REBOL}}==
<
Title: "Date Formatting"
URL: http://rosettacode.org/wiki/Date_format
Line 3,046 ⟶ 3,137:
pick system/locale/months now/month " "
now/day ", " now/year
]</
{{out}}
Line 3,053 ⟶ 3,144:
Sunday, December 6, 2009</pre>
=={{header|RED}}==
<syntaxhighlight lang="red">
Red []
;; zeropad
Line 3,062 ⟶ 3,153:
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]
</syntaxhighlight>
{{out}}<pre>2020-03-25
Wednesday, March 25, 2020
Line 3,070 ⟶ 3,161:
<br>It's up to the programmer to choose whatever version of the '''date''' BIF that best serves the purpose.
===idiomatic version===
<
x = date('S') /*get current date as yyyymmdd */
yyyy = left(x,4) /*pick off year (4 digs).*/
Line 3,081 ⟶ 3,172:
zdd = dd+0 /*remove leading zero from DD */
say weekday',' month zdd"," yyyy /*format date as: Month dd, yyyy*/
/*stick a fork in it, we're done.*/</
{{out}}
<pre>
Line 3,089 ⟶ 3,180:
===compact version===
<
/* ╔══════════════════════════════════════════════════════════════════╗
║ function returns a specific example ║
Line 3,116 ⟶ 3,207:
say date('W')"," date('M') word(date(), 1)"," yyyy
/* [↑] dayofweek Month dd, yyyy*/
/*stick a fork in it, we're done.*/</
'''output''' would be the same as the 1<sup>st</sup> version.
===modern version===
This version can be used with those REXXes that support the '''I''' (ISO) parameter for the '''date''' BIF.
<
say date('I') /*yyyy-mm-dd with leading zeroes.*/
Line 3,127 ⟶ 3,218:
/* [↑] dayofweek Month dd, yyyy*/
/*stick a fork in it, we're done.*/
</syntaxhighlight>
'''output''' would be the same as the 1<sup>st</sup> version.
<br><br>
=={{header|Ring}}==
<syntaxhighlight lang="c">
dateStr = date()
date1 = timelist()[19] + "-" + timelist()[10] + "-" + timelist()[6]
Line 3,139 ⟶ 3,230:
? date1
? date2
/*
timelist() ---> List contains the time and date information.
Index Value
----------------------------
1 - abbreviated weekday name
2 - full weekday name
3 - abbreviated month name
4 - full month name
5 - Date & Time
6 - Day of the month
7 - Hour (24)
8 - Hour (12)
9 - Day of the year
10 - Month of the year
11 - Minutes after hour
12 - AM or PM
13 - Seconds after the hour
14 - Week of the year (sun-sat)
15 - day of the week
16 - date
17 - time
18 - year of the century
19 - year
20 - time zone
21 - percent sign
*/
</syntaxhighlight>
{{out}}
<pre>
Line 3,145 ⟶ 3,264:
2020-07-19
Sunday, July 19, 2020
</pre>
=={{header|RPL}}==
RPL can return the date as a floating point number (format dd.mmyyyy) and can convert it (along with the time) as a string (format "DAY dd.mm.yy hh.mm.ss")
To solve the task, some formatting is then needed.
{{works with|HP|48}}
≪ DATE DUP 1000000 * 10000 MOD "-" +
OVER FP 100 * IP + "-" +
SWAP IP +
≫ '<span style="color:blue">DTSHORT</span>' STO
≪ { "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday" }
{ "MON" "TUE" "WED" "THU" "FRI" "SAT" "SUN" }
DATE TIME TSTR 1 3 SUB POS GET ", " +
{ "January" "February" "March" "April" "May" "June" "July" "August" "September" "October" "November" "December"}
DATE FP 100 * IP GET + " " +
OVER IP + ", " +
DATE 1000000 * 10000 MOD +
≫ '<span style="color:blue">DTLONG</span>' STO
{{out}}
<pre>
2: "2023-8-17"
1: "Thursday, August 17, 2023"
</pre>
Line 3,150 ⟶ 3,292:
Formatting rules: [//www.ruby-doc.org/core/Time.html#method-i-strftime Time#strftime]
<
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('%A, %B %d, %Y')</
{{out}}
<pre>
Line 3,163 ⟶ 3,305:
=={{header|Run BASIC}}==
<
print date$("yyyy-mm-dd")
print date$("dddd");", "; 'return full day of the week (eg. Wednesday
print date$("mmmm");" "; 'return full month name (eg. March)
print date$("dd, yyyy") 'return day, year</
{{out}}
<pre>
Line 3,176 ⟶ 3,318:
=={{header|Rust}}==
Using <code>chrono 0.4.6</code>
<
let now = chrono::Utc::now();
println!("{}", now.format("%Y-%m-%d"));
println!("{}", now.format("%A, %B %d, %Y"));
}</
=={{header|Scala}}==
<syntaxhighlight lang
import java.util.Date
val now=new Date()
println("%tF".format(now))
println("%1$tA, %1$tB %1$td, %1$tY".format(now))</
{{out}}
<pre>
2023-04-17
Monday, April 17, 2023
</pre>
=={{header|Scheme}}==
Line 3,191 ⟶ 3,342:
{{works with|Guile|2.0.13}}
<
(lambda (lt)
(strftime "%Y-%m-%d" (localtime lt))))
Line 3,208 ⟶ 3,359:
(display (long-date dt))(newline))))
</syntaxhighlight>
=={{header|Seed7}}==
<
include "time.s7i";
Line 3,224 ⟶ 3,375:
writeln(strDate(now));
writeln(days[dayOfWeek(now)] <& ", " <& months[now.month] <& " " <& now.day <& ", " <& now.year);
end func;</
=={{header|SenseTalk}}==
<
put formattedTime( "[year]-[month]-[day]", the date)
put formattedTime( "[weekday], [month name] [day], [year]", the date)
</syntaxhighlight>
{{out}}
<pre>2019-12-18
Line 3,237 ⟶ 3,388:
=={{header|Shiny}}==
<
say time.format 'l, F j, Y' time.now</
=={{header|Sidef}}==
<
say time.ctime;
say time.strftime("%Y-%m-%d");
say time.strftime("%A, %B %d, %Y");</
{{out}}
<pre>
Line 3,255 ⟶ 3,406:
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.
<
d := Date today.
d printFormat: #(3 2 1 $- 1 1 2).
(d weekday asString), ', ', (d monthName), ' ', (d dayOfMonth asString), ', ', (d year asString)</
{{works with|Smalltalk/X}}
<
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:#de. Stdout cr.
d printOn:Stdout format:'%(DayName), %(MonthName) %d, %y' language:#fr. Stdout cr.</
{{out}}
<pre>2020-12-17
Line 3,270 ⟶ 3,421:
Donnerstag, Dezember 17, 2020
Vendredi, Décembre 17, 2020</pre>
=={{header|SparForte}}==
As a structured script. Does not use l10n package.
<syntaxhighlight lang="ada">#!/usr/local/bin/spar
pragma annotate( summary, "dateformat")
@( description, "Display the current date in the formats of '2007-11-10' " )
@( description, "and 'Sunday, November 10, 2007'." )
@( see_also, "http://rosettacode.org/wiki/Date_format" )
@( "Ken O. Burtch" );
pragma license( unrestricted );
pragma restriction( no_external_commands );
procedure dateformat is
function Month_Image (Month : calendar.month_number) return string is
begin
case Month is
when 1 => return "January";
when 2 => return "February";
when 3 => return "March";
when 4 => return "April";
when 5 => return "May";
when 6 => return "June";
when 7 => return "July";
when 8 => return "August";
when 9 => return "September";
when 10 => return "October";
when 11 => return "November";
when others => return "December";
end case;
end Month_Image;
function Day_Image (Day : integer) return string is
begin
case Day is
when 0 => return "Monday";
when 1 => return "Tuesday";
when 2 => return "Wednesday";
when 3 => return "Thursday";
when 4 => return "Friday";
when 5 => return "Saturday";
when others => return "Sunday";
end case;
end Day_Image;
Today : constant calendar.time := calendar.clock;
begin
--put_line(
--Put_Line (Image (Today) (1..10));
put( calendar.year( Today ), "9999" ) @( "-" )
@( calendar.month( Today ), "99" ) @( "-" )
@( calendar.day( Today ), "99" );
new_line;
put_line(
Day_Image( calendar.day_of_week( Today ) ) & ", " &
Month_Image( calendar.month( Today ) ) &
strings.image( calendar.day( Today ) ) & "," &
strings.image( calendar.year( Today ) ) );
end dateformat;</syntaxhighlight>
=={{header|SQL}}==
{{works with|Oracle}}
<
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;
</syntaxhighlight>
<pre>
Line 3,294 ⟶ 3,504:
Formatting rules: http://www.standardml.org/Basis/date.html#SIG:DATE.fmt:VAL
<
print (Date.fmt "%A, %B %d, %Y" (Date.fromTimeLocal (Time.now ())) ^ "\n");</
{{out}}
<pre>
Line 3,306 ⟶ 3,516:
Stata has many ways to format dates, see [https://www.stata.com/help.cgi?Datetime_display_formats Datetime display formats] in the documentation.
<
display %tdDayname,_Month_dd,_CCYY td($S_DATE)</
=={{header|Suneido}}==
<
Date().LongDate() --> "Tuesday, March 16, 2010" </
=={{header|Swift}}==
<
extension String {
func toStandardDateWithDateFormat(format: String) -> String {
Line 3,324 ⟶ 3,534:
}
let date = "2015-08-28".toStandardDateWithDateFormat("yyyy-MM-dd")</
{{out}}
Line 3,332 ⟶ 3,542:
=={{header|Tcl}}==
<
puts [clock format $now -format "%Y-%m-%d"]
puts [clock format $now -format "%A, %B %d, %Y"]</
=={{header|Terraform}}==
<
today = timestamp()
}
Line 3,347 ⟶ 3,557:
output "us-long" {
value = formatdate("EEEE, MMMM D, YYYY", local.today)
}</
{{Out}}
Line 3,358 ⟶ 3,568:
=={{header|TUSCRIPT}}==
<
$$ MODE TUSCRIPT
SET dayofweek = DATE (today,day,month,year,number)
Line 3,386 ⟶ 3,596:
PRINT format1
PRINT format2
</syntaxhighlight>
{{out}}
<pre>
Line 3,394 ⟶ 3,604:
=={{header|UNIX Shell}}==
<
date +"%A, %B %d, %Y"</
On a new enough system <code>%F</code> is equivalent to <code>%Y-%m-%d</code>
<
<!-- ENHANCE-ME: what is new enough for %F ? For example it doesn't appear in these bits of POSIX,
Line 3,408 ⟶ 3,618:
{{works with|Cygnus/X Ursa}}
Cygnus/X Ursa can import and call Java classes.
<
[Oracle Corporation JVM 1.8.0_51 on Mac OS X 10.10.5 x86_64]
> import "java.util.Date"
Line 3,420 ⟶ 3,630:
> out (sdf.format d) endl console
Saturday, July 23, 2016
> _</
=={{header|Ursala}}==
The method is to transform a date in standard format returned by the library function, now.
<
#import cli
Line 3,440 ⟶ 3,650:
#show+
main = <.text_form,numeric_form> now0</
{{out}}
<pre>Wednesday, June 24, 2009
Line 3,447 ⟶ 3,657:
=={{header|VB-DOS|PDS 7.1 BASIC}}==
{{works with|Visual Basic for DOS and PDS 7.1}}
<syntaxhighlight lang="vb">
OPTION EXPLICIT
Line 3,486 ⟶ 3,696:
END
</syntaxhighlight>
=={{header|VBA}}==
<
Debug.Print Format(Date, "yyyy-mm-dd")
Debug.Print Format(Date, "dddd, mmmm dd yyyy")
End Function</
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
'YYYY-MM-DD format
WScript.StdOut.WriteLine Year(Date) & "-" & Right("0" & Month(Date),2) & "-" & Right("0" & Day(Date),2)
Line 3,502 ⟶ 3,712:
'Weekday_Name, Month_Name DD, YYYY format
WScript.StdOut.WriteLine FormatDateTime(Now,1)
</syntaxhighlight>
{{Out}}
Line 3,513 ⟶ 3,723:
Display current date in format "2007-11-10":
<
Display current date in format "Sunday, November 10, 2007" (Requires VEDIT 6.2):
<
#1 = Date_Day
#2 = Date_Month
Line 3,546 ⟶ 3,756:
// Display the date string
RT(1) M(", ") RT(2) M(" ") NT(#1, LEFT+NOCR) M(",") NT(#3)</
To insert the date string into edit buffer instead of displaying it, replace the last line with this:
<
=={{header|Vim Script}}==
See `:help strftime` - this function uses the C strftime() arguments' format.
<syntaxhighlight lang="vim">
echo strftime("%Y-%m-%d")
echo strftime("%A, %B %d, %Y")
</syntaxhighlight>
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">import time
fn main() {
println(time.now().custom_format("YYYY-MM-DD"))
println(time.now().custom_format("dddd, MMMM D, YYYY"))
}</syntaxhighlight>
{{out}}
<pre>
2011-12-02
Friday, December 2, 2011
</pre>
=={{header|Wren}}==
{{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.
<
import "./date" for Date
var args = Process.arguments
Line 3,564 ⟶ 3,795:
var current = Date.parse(args[0])
System.print(current.format(Date.isoDate))
System.print(current.format("dddd|, |mmmm| |d|, |yyyy"))</
{{out}}
Line 3,574 ⟶ 3,805:
=={{header|XPL0}}==
<
int CpuReg, Year, Month, Day, DName, MName, WDay;
[CpuReg:= GetReg; \access CPU registers
Line 3,592 ⟶ 3,823:
Text(0, DName(WDay)); Text(0, ", "); Text(0, MName(Month)); Text(0, " ");
IntOut(0, Day); Text(0, ", "); IntOut(0, Year); CrLf(0);
]</
{{out}}
Line 3,601 ⟶ 3,832:
=={{header|Yabasic}}==
<
n = token(date$, n$(), "-")
Line 3,628 ⟶ 3,859:
return month$(int(n/3) + 1)
end sub</
=={{header|zkl}}==
<
//--> "2014-02-28" (ISO format)</
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.
<
//--> "Friday, the 28th of February 2014"</
<
"%s, %s %d, %d".fmt(D.dayName(D.weekDay(y,m,d)),
D.monthName(m), d,y)
//-->"Friday, February 28, 2014"</
=={{header|zonnon}}==
<
module Main;
import System;
Line 3,653 ⟶ 3,884:
System.Console.WriteLine("{0}, {1}",now.DayOfWeek,now.ToString("MMMM dd, yyyy"));
end Main.
</syntaxhighlight>
{{Out}}
<pre>
|