Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
3
Task/Date-format/00-META.yaml
Normal file
3
Task/Date-format/00-META.yaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Date_format
|
||||
note: Text processing
|
||||
6
Task/Date-format/00-TASK.txt
Normal file
6
Task/Date-format/00-TASK.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
;Task:
|
||||
Display the current date in the formats of:
|
||||
:::* '''2007-11-23''' and
|
||||
:::* '''Friday, November 23, 2007'''
|
||||
<br><br>
|
||||
|
||||
2
Task/Date-format/11l/date-format.11l
Normal file
2
Task/Date-format/11l/date-format.11l
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
print(Time().format(‘YYYY-MM-DD’))
|
||||
print(Time().strftime(‘%A, %B %e, %Y’))
|
||||
108
Task/Date-format/68000-Assembly/date-format.68000
Normal file
108
Task/Date-format/68000-Assembly/date-format.68000
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
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.
|
||||
JSR PrintChar
|
||||
MOVE.B #'0',D0
|
||||
JSR PrintChar
|
||||
|
||||
LEA BIOS_YEAR,A1
|
||||
MOVE.B (A1)+,D0 ;stores last 2 digits of year into D0, in binary coded decimal
|
||||
JSR UnpackNibbles8 ;separate the digits into high and low nibbles: D0 = 00020001
|
||||
ADD.L #$00300030,D0 ;convert both numerals to their ascii equivalents.
|
||||
SWAP D0 ;print the "2" first
|
||||
JSR PrintChar
|
||||
SWAP D0 ;then the "1"
|
||||
JSR PrintChar
|
||||
|
||||
MOVE.B #'-',D0
|
||||
JSR PrintChar
|
||||
|
||||
MOVE.B (A1)+,D0 ;get the month
|
||||
JSR UnpackNibbles8
|
||||
ADD.L #$00300030,D0
|
||||
SWAP D0
|
||||
JSR PrintChar
|
||||
SWAP D0
|
||||
JSR PrintChar
|
||||
|
||||
MOVE.B #'-',D0
|
||||
JSR PrintChar
|
||||
|
||||
MOVE.B (A1)+,D0 ;get the day
|
||||
JSR UnpackNibbles8
|
||||
ADD.L #$00300030,D0
|
||||
SWAP D0
|
||||
JSR PrintChar
|
||||
SWAP D0
|
||||
JSR PrintChar
|
||||
|
||||
;now the date is printed.
|
||||
|
||||
;Now do it again only written out:
|
||||
jsr NewLine
|
||||
|
||||
CLR.L D0 ;reset D0
|
||||
MOVE.B (A1),D0 ;A1 happens to point to the weekday
|
||||
LSL.W #2,D0 ;we are indexing into a table of longs
|
||||
LEA Days_Lookup,A2
|
||||
LEA (A2,D0),A2
|
||||
MOVEA.L (A2),A3 ;dereference the pointer into A3, which the PrintString routine takes as an argument.
|
||||
|
||||
JSR PrintString
|
||||
|
||||
CLR.L D0
|
||||
LEA BIOS_MONTH,A1 ;GET THE MONTH
|
||||
MOVE.B (A1)+,D0
|
||||
LSL.W #2,D0
|
||||
LEA Months_Lookup,A2
|
||||
LEA (A2,D0),A2
|
||||
MOVEA.L (A2),A3
|
||||
|
||||
JSR PrintString
|
||||
|
||||
MOVE.B (A1),D0 ;GET THE DAY
|
||||
JSR UnpackNibbles8
|
||||
ADD.L #$00300030,D0
|
||||
SWAP D0
|
||||
JSR PrintChar
|
||||
SWAP D0
|
||||
JSR PrintChar
|
||||
|
||||
MOVE.B #',',D0
|
||||
JSR PrintChar
|
||||
MOVE.B #' ',D0
|
||||
JSR PrintChar
|
||||
|
||||
MOVE.B #'2',D0
|
||||
JSR PrintChar
|
||||
MOVE.B #'0',D0
|
||||
JSR PrintChar
|
||||
|
||||
LEA BIOS_YEAR,A1
|
||||
MOVE.B (A1)+,D0 ;stores last 2 digits of year into D0, in binary coded decimal
|
||||
JSR UnpackNibbles8 ;separate the digits into high and low nibbles: D0 = 00020001
|
||||
ADD.L #$00300030,D0 ;convert both numerals to their ascii equivalents.
|
||||
SWAP D0 ;print the "2" first
|
||||
JSR PrintChar
|
||||
SWAP D0 ;then the "1"
|
||||
JSR PrintChar
|
||||
|
||||
forever:
|
||||
bra forever ;trap the program counter
|
||||
|
||||
UnpackNibbles8:
|
||||
; INPUT: D0 = THE VALUE YOU WISH TO UNPACK.
|
||||
; HIGH NIBBLE IN HIGH WORD OF D0, LOW NIBBLE IN LOW WORD. SWAP D0 TO GET THE OTHER HALF.
|
||||
pushWord D1
|
||||
CLR.W D1
|
||||
MOVE.B D0,D1
|
||||
CLR.L D0
|
||||
MOVE.B D1,D0 ;now D0 = D1 = $000000II, where I = input
|
||||
|
||||
AND.B #$F0,D0 ;chop off bottom nibble
|
||||
LSR.B #4,D0 ;downshift top nibble into bottom nibble of the word
|
||||
SWAP D0 ;store in high word
|
||||
AND.B #$0F,D1 ;chop off bottom nibble
|
||||
MOVE.B D1,D0 ;store in low word
|
||||
popWord D1
|
||||
rts
|
||||
4
Task/Date-format/8th/date-format.8th
Normal file
4
Task/Date-format/8th/date-format.8th
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
d:new
|
||||
"%Y-%M-%D" over d:format . cr
|
||||
"%W, %N %D, %Y" over d:format . cr
|
||||
bye
|
||||
320
Task/Date-format/AArch64-Assembly/date-format.aarch64
Normal file
320
Task/Date-format/AArch64-Assembly/date-format.aarch64
Normal file
|
|
@ -0,0 +1,320 @@
|
|||
/* ARM assembly AARCH64 Raspberry PI 3B */
|
||||
/* program dateFormat64.s */
|
||||
|
||||
|
||||
/*******************************************/
|
||||
/* Constantes file */
|
||||
/*******************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly*/
|
||||
.include "../includeConstantesARM64.inc"
|
||||
|
||||
.equ GETTIME, 169 // call system linux gettimeofday
|
||||
|
||||
/*******************************************/
|
||||
/* Structures */
|
||||
/********************************************/
|
||||
/* example structure time */
|
||||
.struct 0
|
||||
timeval_sec: //
|
||||
.struct timeval_sec + 8
|
||||
timeval_usec: //
|
||||
.struct timeval_usec + 8
|
||||
timeval_end:
|
||||
.struct 0
|
||||
timezone_min: //
|
||||
.struct timezone_min + 8
|
||||
timezone_dsttime: //
|
||||
.struct timezone_dsttime + 8
|
||||
timezone_end:
|
||||
|
||||
/*********************************/
|
||||
/* Initialized data */
|
||||
/*********************************/
|
||||
.data
|
||||
szMessError: .asciz "Error detected !!!!. \n"
|
||||
szMessResult: .asciz "Date : @/@/@ \n" // message result
|
||||
szMessResult1: .asciz "Date day : @ @ @ @ \n" // message result
|
||||
szJan: .asciz "Janvier"
|
||||
szFev: .asciz "Fèvrier"
|
||||
szMars: .asciz "Mars"
|
||||
szAvril: .asciz "Avril"
|
||||
szMai: .asciz "Mai"
|
||||
szJuin: .asciz "Juin"
|
||||
szJuil: .asciz "Juillet"
|
||||
szAout: .asciz "Aout"
|
||||
szSept: .asciz "Septembre"
|
||||
szOct: .asciz "Octobre"
|
||||
szNov: .asciz "Novembre"
|
||||
szDec: .asciz "Décembre"
|
||||
szLundi: .asciz "Lundi"
|
||||
szMardi: .asciz "Mardi"
|
||||
szMercredi: .asciz "Mercredi"
|
||||
szJeudi: .asciz "Jeudi"
|
||||
szVendredi: .asciz "Vendredi"
|
||||
szSamedi: .asciz "Samedi"
|
||||
szDimanche: .asciz "Dimanche"
|
||||
szCarriageReturn: .asciz "\n"
|
||||
.align 4
|
||||
tbDayMonthYear: .quad 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335
|
||||
.quad 366, 397, 425, 456, 486, 517, 547, 578, 609, 639, 670, 700
|
||||
.quad 731, 762, 790, 821, 851, 882, 912, 943, 974,1004,1035,1065
|
||||
.quad 1096,1127,1155,1186,1216,1247,1277,1308,1339,1369,1400,1430
|
||||
tbMonthName: .quad szJan
|
||||
.quad szFev
|
||||
.quad szMars
|
||||
.quad szAvril
|
||||
.quad szMai
|
||||
.quad szJuin
|
||||
.quad szJuil
|
||||
.quad szAout
|
||||
.quad szSept
|
||||
.quad szOct
|
||||
.quad szNov
|
||||
.quad szDec
|
||||
tbDayName: .quad szLundi
|
||||
.quad szMardi
|
||||
.quad szMercredi
|
||||
.quad szJeudi
|
||||
.quad szVendredi
|
||||
.quad szSamedi
|
||||
.quad szDimanche
|
||||
|
||||
/*********************************/
|
||||
/* UnInitialized data */
|
||||
/*********************************/
|
||||
.bss
|
||||
.align 4
|
||||
stTVal: .skip timeval_end
|
||||
stTZone: .skip timezone_end
|
||||
sZoneConv: .skip 24
|
||||
/*********************************/
|
||||
/* code section */
|
||||
/*********************************/
|
||||
.text
|
||||
.global main
|
||||
main: // entry of program
|
||||
ldr x0,qAdrstTVal
|
||||
ldr x1,qAdrstTZone
|
||||
mov x8,#GETTIME
|
||||
svc 0
|
||||
cmp x0,#-1 // error ?
|
||||
beq 99f
|
||||
ldr x1,qAdrstTVal
|
||||
ldr x0,[x1,#timeval_sec] // timestamp in second
|
||||
bl dateFormatNum
|
||||
ldr x0,[x1,#timeval_sec] // timestamp in second
|
||||
bl dateFormatAlpha
|
||||
ldr x0,qTStest1
|
||||
bl dateFormatNum
|
||||
ldr x0,qTStest1
|
||||
bl dateFormatAlpha
|
||||
ldr x0,qTStest2
|
||||
bl dateFormatNum
|
||||
ldr x0,qTStest2
|
||||
bl dateFormatAlpha
|
||||
ldr x0,qTStest3
|
||||
bl dateFormatNum
|
||||
ldr x0,qTStest3
|
||||
bl dateFormatAlpha
|
||||
b 100f
|
||||
99:
|
||||
ldr x0,qAdrszMessError
|
||||
bl affichageMess
|
||||
100: // standard end of the program
|
||||
mov x0,#0 // return code
|
||||
mov x8,#EXIT // request to exit program
|
||||
svc 0 // perform the system call
|
||||
|
||||
qAdrszMessError: .quad szMessError
|
||||
qAdrstTVal: .quad stTVal
|
||||
qAdrstTZone: .quad stTZone
|
||||
qAdrszCarriageReturn: .quad szCarriageReturn
|
||||
qAdrsZoneConv: .quad sZoneConv
|
||||
qTStest1: .quad 1609508339 // 01/01/2021
|
||||
qTStest2: .quad 1657805939 // 14/07/2022
|
||||
qTStest3: .quad 1767221999 // 31/12/2025
|
||||
/******************************************************************/
|
||||
/* date format numeric */
|
||||
/******************************************************************/
|
||||
/* x0 contains the timestamp in seconds */
|
||||
dateFormatNum:
|
||||
stp x1,lr,[sp,-16]! // save registers
|
||||
ldr x2,qSecJan2020
|
||||
sub x0,x0,x2 // total secondes to 01/01/2020
|
||||
mov x1,60
|
||||
udiv x0,x0,x1 // divide secondes
|
||||
udiv x0,x0,x1 // divide minutes
|
||||
mov x1,#24
|
||||
udiv x0,x0,x1 // divide hours
|
||||
mov x11,x0
|
||||
mov x1,#(365 * 4 + 1)
|
||||
udiv x9,x0,x1
|
||||
lsl x9,x9,#2 // multiply by 4 = year1
|
||||
mov x1,#(365 * 4 + 1)
|
||||
udiv x2,x11,x1
|
||||
msub x10,x2,x1,x11
|
||||
|
||||
ldr x1,qAdrtbDayMonthYear
|
||||
mov x2,#3
|
||||
mov x3,#12
|
||||
1:
|
||||
mul x11,x3,x2
|
||||
ldr x4,[x1,x11,lsl 3] // load days by year
|
||||
cmp x10,x4
|
||||
bge 2f
|
||||
sub x2,x2,1
|
||||
cbnz x2,1b
|
||||
2: // x2 = year2
|
||||
mov x5,11
|
||||
mul x11,x3,x2
|
||||
lsl x11,x11,3
|
||||
add x11,x11,x1 // table address
|
||||
3:
|
||||
ldr x4,[x11,x5,lsl 3] // load days by month
|
||||
cmp x10,x4
|
||||
bge 4f
|
||||
subs x5,x5,1
|
||||
bne 3b
|
||||
4: // x5 = month - 1
|
||||
mul x11,x3,x2
|
||||
add x11,x11,x5
|
||||
ldr x1,qAdrtbDayMonthYear
|
||||
ldr x3,[x1,x11,lsl 3]
|
||||
sub x0,x10,x3
|
||||
add x0,x0,1 // final compute day
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl conversion10 // this function do not zero final
|
||||
ldr x0,qAdrszMessResult
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl strInsertAtCharInc // insert result at first // character
|
||||
mov x3,x0
|
||||
add x0,x5,1 // final compute month
|
||||
cmp x0,12
|
||||
sub x1,x0,12
|
||||
csel x0,x1,x0,gt
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl conversion10
|
||||
mov x0,x3
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl strInsertAtCharInc // insert result at next // character
|
||||
mov x3,x0
|
||||
ldr x11,qYearStart
|
||||
add x0,x9,x11
|
||||
add x0,x0,x2 // final compute year = 2020 + yeax1 + yeax2
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl conversion10
|
||||
mov x0,x3
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl strInsertAtCharInc // insert result at next // character
|
||||
bl affichageMess
|
||||
100:
|
||||
ldp x1,lr,[sp],16 // restaur 2 registers
|
||||
ret // return to address lr x30
|
||||
qAdrszMessResult: .quad szMessResult
|
||||
/******************************************************************/
|
||||
/* date format alphanumeric */
|
||||
/******************************************************************/
|
||||
/* x0 contains the timestamp in seconds */
|
||||
dateFormatAlpha:
|
||||
stp x1,lr,[sp,-16]! // save registers
|
||||
ldr x2,qSecJan2020
|
||||
sub x0,x0,x2 // total secondes to 01/01/2020
|
||||
mov x6,x0
|
||||
mov x1,60
|
||||
udiv x0,x0,x1
|
||||
udiv x0,x0,x1
|
||||
mov x1,24
|
||||
udiv x0,x0,x1
|
||||
mov x7,x0
|
||||
mov x1,(365 * 4 + 1)
|
||||
udiv x9,x0,x1
|
||||
lsl x9,x9,#2 // multiply by 4 = year1
|
||||
mov x1,(365 * 4 + 1)
|
||||
udiv x0,x7,x1
|
||||
msub x10,x0,x1,x7
|
||||
ldr x1,qAdrtbDayMonthYear
|
||||
mov x8,3
|
||||
mov x3,12
|
||||
1:
|
||||
mul x7,x3,x8
|
||||
ldr x4,[x1,x7,lsl 3] // load days by year
|
||||
cmp x10,x4
|
||||
bge 2f
|
||||
sub x8,x8,1
|
||||
cmp x8,0
|
||||
bne 1b
|
||||
2: // x8 = yeax2
|
||||
mov x5,#11
|
||||
mul x7,x3,x8
|
||||
lsl x7,x7,3
|
||||
add x7,x7,x1
|
||||
3:
|
||||
ldr x4,[x7,x5,lsl 3] // load days by month
|
||||
cmp x10,x4
|
||||
bge 4f
|
||||
subs x5,x5,1
|
||||
bne 3b
|
||||
4: // x5 = month - 1
|
||||
|
||||
mov x0,x6 // number secondes depuis 01/01/2020
|
||||
ldr x1,qNbSecByDay
|
||||
udiv x0,x6,x1
|
||||
mov x1,7
|
||||
udiv x2,x0,x1
|
||||
msub x3,x2,x1,x0
|
||||
add x2,x3,2
|
||||
cmp x2,7
|
||||
sub x3,x2,7
|
||||
csel x2,x3,x2,ge
|
||||
ldr x1,qAdrtbDayName
|
||||
ldr x1,[x1,x2,lsl 3]
|
||||
ldr x0,qAdrszMessResult1
|
||||
|
||||
bl strInsertAtCharInc // insert result at next // character
|
||||
mov x3,x0
|
||||
mov x7,12
|
||||
mul x11,x7,x8
|
||||
add x11,x11,x5
|
||||
ldr x1,qAdrtbDayMonthYear
|
||||
ldr x7,[x1,x11,lsl 3]
|
||||
sub x0,x10,x7
|
||||
add x0,x0,1 // final compute day
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl conversion10 // this function do not zero final
|
||||
mov x0,x3
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl strInsertAtCharInc // insert result at first // character
|
||||
mov x3,x0
|
||||
ldr x1,qAdrtbMonthName
|
||||
cmp x5,12
|
||||
sub x2,x5,12
|
||||
csel x5,x2,x5,ge
|
||||
ldr x1,[x1,x5,lsl 3] // month name
|
||||
mov x0,x3
|
||||
bl strInsertAtCharInc // insert result at first // character
|
||||
mov x3,x0
|
||||
ldr x0,qYearStart
|
||||
add x0,x0,x8
|
||||
add x0,x0,x9 // final compute year = 2020 + yeax1 + yeax2
|
||||
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl conversion10 // this function do not zero final
|
||||
mov x0,x3
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl strInsertAtCharInc // insert result at first // character
|
||||
bl affichageMess
|
||||
100:
|
||||
ldp x1,lr,[sp],16 // restaur 2 registers
|
||||
ret // return to address lr x30
|
||||
qAdrszMessResult1: .quad szMessResult1
|
||||
qSecJan2020: .quad 1577836800
|
||||
qAdrtbDayMonthYear: .quad tbDayMonthYear
|
||||
qYearStart: .quad 2020
|
||||
qAdrtbMonthName: .quad tbMonthName
|
||||
qAdrtbDayName: .quad tbDayName
|
||||
qNbSecByDay: .quad 3600 * 24
|
||||
/********************************************************/
|
||||
/* File Include fonctions */
|
||||
/********************************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly */
|
||||
.include "../includeARM64.inc"
|
||||
21
Task/Date-format/ABAP/date-format.abap
Normal file
21
Task/Date-format/ABAP/date-format.abap
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
report zdate.
|
||||
data: lv_month type string,
|
||||
lv_weekday type string,
|
||||
lv_date type string,
|
||||
lv_day type c.
|
||||
|
||||
call function 'DATE_COMPUTE_DAY'
|
||||
exporting date = sy-datum
|
||||
importing day = lv_day.
|
||||
select single ltx from t247 into lv_month
|
||||
where spras = sy-langu and
|
||||
mnr = sy-datum+4(2).
|
||||
|
||||
select single langt from t246 into lv_weekday
|
||||
where sprsl = sy-langu and
|
||||
wotnr = lv_day.
|
||||
|
||||
concatenate lv_weekday ', ' lv_month ' ' sy-datum+6(2) ', ' sy-datum(4) into lv_date respecting blanks.
|
||||
write lv_date.
|
||||
concatenate sy-datum(4) '-' sy-datum+4(2) '-' sy-datum+6(2) into lv_date.
|
||||
write / lv_date.
|
||||
23
Task/Date-format/ALGOL-68/date-format.alg
Normal file
23
Task/Date-format/ALGOL-68/date-format.alg
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# 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);
|
||||
|
||||
FORMAT # some useful format declarations #
|
||||
ymd repr = $4d,"-"2d,"-"2d$,
|
||||
month repr = $c("January","February","March","April","May","June","July",
|
||||
"August","September","October","November","December")$,
|
||||
week day repr = $c("Sunday","Monday","Tuesday","Wednesday",
|
||||
"Thursday","Friday","Saturday")$,
|
||||
dmdy repr = $f(week day repr)", "f(month repr)" "g(-0)", "g(-4)$,
|
||||
|
||||
mon = $c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")$,
|
||||
wday = $c("Sun","Mon","Tue","Wed","Thu","Fri","Sat")$,
|
||||
tz = $c("MSK","MSD")$,
|
||||
unix time repr = $f(wday)" "f(mon)z-d," "dd,":"dd,":"dd," "f(tz)" "dddd$;
|
||||
|
||||
[]INT now = local time;
|
||||
|
||||
printf((ymd repr, now[year OF tm:mday OF tm], $l$));
|
||||
printf((dmdy repr, now[wday OF tm], now[mon OF tm], now[mday OF tm], now[year OF tm], $l$));
|
||||
|
||||
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$))
|
||||
347
Task/Date-format/ARM-Assembly/date-format.arm
Normal file
347
Task/Date-format/ARM-Assembly/date-format.arm
Normal file
|
|
@ -0,0 +1,347 @@
|
|||
/* ARM assembly Raspberry PI */
|
||||
/* program dateFormat.s */
|
||||
|
||||
/* REMARK 1 : this program use routines in a include file
|
||||
see task Include a file language arm assembly
|
||||
for the routine affichageMess conversion10
|
||||
see at end of this program the instruction include */
|
||||
|
||||
/*******************************************/
|
||||
/* Constantes */
|
||||
/*******************************************/
|
||||
.equ STDOUT, 1 @ Linux output console
|
||||
.equ EXIT, 1 @ Linux syscall
|
||||
.equ WRITE, 4 @ Linux syscall
|
||||
.equ BRK, 0x2d @ Linux syscall
|
||||
.equ CHARPOS, '@'
|
||||
|
||||
.equ GETTIME, 0x4e @ call system linux gettimeofday
|
||||
|
||||
/*******************************************/
|
||||
/* Structures */
|
||||
/********************************************/
|
||||
/* example structure time */
|
||||
.struct 0
|
||||
timeval_sec: @
|
||||
.struct timeval_sec + 4
|
||||
timeval_usec: @
|
||||
.struct timeval_usec + 4
|
||||
timeval_end:
|
||||
.struct 0
|
||||
timezone_min: @
|
||||
.struct timezone_min + 4
|
||||
timezone_dsttime: @
|
||||
.struct timezone_dsttime + 4
|
||||
timezone_end:
|
||||
|
||||
/*********************************/
|
||||
/* Initialized data */
|
||||
/*********************************/
|
||||
.data
|
||||
szMessError: .asciz "Error detected !!!!. \n"
|
||||
szMessResult: .asciz "Date : @/@/@ \n" @ message result
|
||||
szMessResult1: .asciz "Date day : @ @ @ @ \n" @ message result
|
||||
szJan: .asciz "Janvier"
|
||||
szFev: .asciz "Février"
|
||||
szMars: .asciz "Mars"
|
||||
szAvril: .asciz "Avril"
|
||||
szMai: .asciz "Mai"
|
||||
szJuin: .asciz "Juin"
|
||||
szJuil: .asciz "Juillet"
|
||||
szAout: .asciz "Aout"
|
||||
szSept: .asciz "Septembre"
|
||||
szOct: .asciz "Octobre"
|
||||
szNov: .asciz "Novembre"
|
||||
szDec: .asciz "Décembre"
|
||||
szLundi: .asciz "Lundi"
|
||||
szMardi: .asciz "Mardi"
|
||||
szMercredi: .asciz "Mercredi"
|
||||
szJeudi: .asciz "Jeudi"
|
||||
szVendredi: .asciz "Vendredi"
|
||||
szSamedi: .asciz "Samedi"
|
||||
szDimanche: .asciz "Dimanche"
|
||||
szCarriageReturn: .asciz "\n"
|
||||
.align 4
|
||||
tbDayMonthYear: .int 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335
|
||||
.int 366, 397, 425, 456, 486, 517, 547, 578, 609, 639, 670, 700
|
||||
.int 731, 762, 790, 821, 851, 882, 912, 943, 974,1004,1035,1065
|
||||
.int 1096,1127,1155,1186,1216,1247,1277,1308,1339,1369,1400,1430
|
||||
tbMonthName: .int szJan
|
||||
.int szFev
|
||||
.int szMars
|
||||
.int szAvril
|
||||
.int szMai
|
||||
.int szJuin
|
||||
.int szJuil
|
||||
.int szAout
|
||||
.int szSept
|
||||
.int szOct
|
||||
.int szNov
|
||||
.int szDec
|
||||
tbDayName: .int szLundi
|
||||
.int szMardi
|
||||
.int szMercredi
|
||||
.int szJeudi
|
||||
.int szVendredi
|
||||
.int szSamedi
|
||||
.int szDimanche
|
||||
|
||||
/*********************************/
|
||||
/* UnInitialized data */
|
||||
/*********************************/
|
||||
.bss
|
||||
.align 4
|
||||
stTVal: .skip timeval_end
|
||||
stTZone: .skip timezone_end
|
||||
sZoneConv: .skip 100
|
||||
/*********************************/
|
||||
/* code section */
|
||||
/*********************************/
|
||||
.text
|
||||
.global main
|
||||
main: @ entry of program
|
||||
ldr r0,iAdrstTVal
|
||||
ldr r1,iAdrstTZone
|
||||
mov r7,#GETTIME
|
||||
svc 0
|
||||
cmp r0,#-1 @ error ?
|
||||
beq 99f
|
||||
ldr r1,iAdrstTVal
|
||||
ldr r0,[r1,#timeval_sec] @ timestemp in second
|
||||
bl dateFormatNum
|
||||
ldr r0,[r1,#timeval_sec] @ timestemp in second
|
||||
bl dateFormatAlpha
|
||||
ldr r0,iTStest1
|
||||
bl dateFormatNum
|
||||
ldr r0,iTStest1
|
||||
bl dateFormatAlpha
|
||||
ldr r0,iTStest2
|
||||
bl dateFormatNum
|
||||
ldr r0,iTStest2
|
||||
bl dateFormatAlpha
|
||||
ldr r0,iTStest3
|
||||
bl dateFormatNum
|
||||
ldr r0,iTStest3
|
||||
bl dateFormatAlpha
|
||||
b 100f
|
||||
99:
|
||||
ldr r0,iAdrszMessError
|
||||
bl affichageMess
|
||||
100: @ standard end of the program
|
||||
mov r0,#0 @ return code
|
||||
mov r7,#EXIT @ request to exit program
|
||||
svc 0 @ perform the system call
|
||||
|
||||
iAdrszMessError: .int szMessError
|
||||
iAdrstTVal: .int stTVal
|
||||
iAdrstTZone: .int stTZone
|
||||
iAdrszCarriageReturn: .int szCarriageReturn
|
||||
iAdrsZoneConv: .int sZoneConv
|
||||
iTStest1: .int 1609508339 @ 01/01/2021
|
||||
iTStest2: .int 1657805939 @ 14/07/2022
|
||||
iTStest3: .int 1767221999 @ 31/12/2025
|
||||
/******************************************************************/
|
||||
/* date format numeric */
|
||||
/******************************************************************/
|
||||
/* r0 contains the timestamp in seconds */
|
||||
dateFormatNum:
|
||||
push {r1-r11,lr} @ save registers
|
||||
ldr r2,iSecJan2020
|
||||
sub r0,r0,r2 @ total secondes to 01/01/2020
|
||||
mov r1,#60
|
||||
bl division
|
||||
mov r0,r2
|
||||
mov r6,r3 @ compute secondes
|
||||
mov r1,#60
|
||||
bl division
|
||||
mov r7,r3 @ compute minutes
|
||||
mov r0,r2
|
||||
mov r1,#24
|
||||
bl division
|
||||
mov r8,r3 @ compute hours
|
||||
mov r0,r2
|
||||
mov r11,r0
|
||||
mov r1,#(365 * 4 + 1)
|
||||
bl division
|
||||
lsl r9,r2,#2 @ multiply by 4 = year1
|
||||
mov r1,#(365 * 4 + 1)
|
||||
mov r0,r11
|
||||
bl division
|
||||
mov r10,r3
|
||||
|
||||
ldr r1,iAdrtbDayMonthYear
|
||||
mov r2,#3
|
||||
mov r3,#12
|
||||
1:
|
||||
mul r11,r3,r2
|
||||
ldr r4,[r1,r11,lsl #2] @ load days by year
|
||||
cmp r10,r4
|
||||
bge 2f
|
||||
sub r2,r2,#1
|
||||
cmp r2,#0
|
||||
bne 1b
|
||||
2: @ r2 = year2
|
||||
mov r5,#11
|
||||
mul r11,r3,r2
|
||||
lsl r11,#2
|
||||
add r11,r1 @ table address
|
||||
3:
|
||||
ldr r4,[r11,r5,lsl #2] @ load days by month
|
||||
cmp r10,r4
|
||||
bge 4f
|
||||
subs r5,r5,#1
|
||||
bne 3b
|
||||
4: @ r5 = month - 1
|
||||
mul r11,r3,r2
|
||||
add r11,r5
|
||||
ldr r1,iAdrtbDayMonthYear
|
||||
ldr r3,[r1,r11,lsl #2]
|
||||
sub r0,r10,r3
|
||||
add r0,r0,#1 @ final compute day
|
||||
ldr r1,iAdrsZoneConv
|
||||
bl conversion10 @ this function do not zero final
|
||||
mov r11,#0 @ store zero final
|
||||
strb r11,[r1,r0]
|
||||
ldr r0,iAdrszMessResult
|
||||
ldr r1,iAdrsZoneConv
|
||||
bl strInsertAtCharInc @ insert result at first @ character
|
||||
mov r3,r0
|
||||
add r0,r5,#1 @ final compute month
|
||||
cmp r0,#12
|
||||
subgt r0,#12
|
||||
ldr r1,iAdrsZoneConv
|
||||
bl conversion10
|
||||
mov r11,#0 @ store zero final
|
||||
strb r11,[r1,r0]
|
||||
mov r0,r3
|
||||
ldr r1,iAdrsZoneConv
|
||||
bl strInsertAtCharInc @ insert result at next @ character
|
||||
mov r3,r0
|
||||
ldr r11,iYearStart
|
||||
add r0,r9,r11
|
||||
add r0,r0,r2 @ final compute year = 2020 + year1 + year2
|
||||
ldr r1,iAdrsZoneConv
|
||||
bl conversion10
|
||||
mov r11,#0 @ store zero final
|
||||
strb r11,[r1,r0]
|
||||
mov r0,r3
|
||||
ldr r1,iAdrsZoneConv
|
||||
bl strInsertAtCharInc @ insert result at next @ character
|
||||
bl affichageMess
|
||||
100:
|
||||
pop {r1-r11,lr} @ restaur registers
|
||||
bx lr @ return
|
||||
iAdrszMessResult: .int szMessResult
|
||||
/******************************************************************/
|
||||
/* date format alphanumeric */
|
||||
/******************************************************************/
|
||||
/* r0 contains the timestamp in seconds */
|
||||
dateFormatAlpha:
|
||||
push {r1-r10,lr} @ save registers
|
||||
ldr r2,iSecJan2020
|
||||
sub r0,r0,r2 @ total secondes to 01/01/2020
|
||||
mov r6,r0
|
||||
mov r1,#60
|
||||
bl division
|
||||
mov r0,r2
|
||||
mov r1,#60
|
||||
bl division
|
||||
mov r0,r2
|
||||
mov r1,#24
|
||||
bl division
|
||||
mov r0,r2
|
||||
mov r8,r0
|
||||
mov r1,#(365 * 4 + 1)
|
||||
bl division
|
||||
lsl r9,r2,#2 @ multiply by 4 = year1
|
||||
mov r1,#(365 * 4 + 1)
|
||||
mov r0,r8
|
||||
bl division
|
||||
mov r10,r3 @ reste
|
||||
|
||||
ldr r1,iAdrtbDayMonthYear
|
||||
mov r7,#3
|
||||
mov r3,#12
|
||||
1:
|
||||
mul r8,r3,r7
|
||||
ldr r4,[r1,r8,lsl #2] @ load days by year
|
||||
cmp r10,r4
|
||||
bge 2f
|
||||
sub r7,r7,#1
|
||||
cmp r7,#0
|
||||
bne 1b
|
||||
2: @ r7 = year2
|
||||
mov r5,#11
|
||||
mul r8,r3,r7
|
||||
lsl r8,#2
|
||||
add r8,r1
|
||||
3:
|
||||
ldr r4,[r8,r5,lsl #2] @ load days by month
|
||||
cmp r10,r4
|
||||
bge 4f
|
||||
subs r5,r5,#1
|
||||
bne 3b
|
||||
4: @ r5 = month - 1
|
||||
|
||||
mov r0,r6 @ number secondes depuis 01/01/2020
|
||||
ldr r1,iNbSecByDay
|
||||
bl division
|
||||
mov r0,r2
|
||||
mov r1,#7
|
||||
bl division
|
||||
add r2,r3,#2
|
||||
cmp r2,#7
|
||||
subge r2,#7
|
||||
ldr r1,iAdrtbDayName
|
||||
ldr r1,[r1,r2,lsl #2]
|
||||
ldr r0,iAdrszMessResult1
|
||||
bl strInsertAtCharInc @ insert result at next @ character
|
||||
mov r3,r0
|
||||
mov r8,#12
|
||||
mul r11,r8,r7
|
||||
add r11,r5
|
||||
ldr r1,iAdrtbDayMonthYear
|
||||
ldr r8,[r1,r11,lsl #2]
|
||||
sub r0,r10,r8
|
||||
add r0,r0,#1 @ final compute day
|
||||
ldr r1,iAdrsZoneConv
|
||||
bl conversion10 @ this function do not zero final
|
||||
mov r8,#0 @ store zero final
|
||||
strb r8,[r1,r0]
|
||||
mov r0,r3
|
||||
ldr r1,iAdrsZoneConv
|
||||
bl strInsertAtCharInc @ insert result at first @ character
|
||||
mov r3,r0
|
||||
ldr r1,iAdrtbMonthName
|
||||
cmp r5,#12
|
||||
subge r5,#12
|
||||
ldr r1,[r1,r5,lsl #2] @ month name
|
||||
mov r0,r3
|
||||
bl strInsertAtCharInc @ insert result at first @ character
|
||||
mov r3,r0
|
||||
ldr r0,iYearStart
|
||||
add r0,r7
|
||||
add r0,r9 @ final compute year = 2020 + year1 + year2
|
||||
|
||||
ldr r1,iAdrsZoneConv
|
||||
bl conversion10 @ this function do not zero final
|
||||
mov r8,#0 @ store zero final
|
||||
strb r8,[r1,r0]
|
||||
mov r0,r3
|
||||
ldr r1,iAdrsZoneConv
|
||||
bl strInsertAtCharInc @ insert result at first @ character
|
||||
bl affichageMess
|
||||
100:
|
||||
pop {r1-r10,lr} @ restaur registers
|
||||
bx lr @ return
|
||||
iAdrszMessResult1: .int szMessResult1
|
||||
iSecJan2020: .int 1577836800
|
||||
iAdrtbDayMonthYear: .int tbDayMonthYear
|
||||
iYearStart: .int 2020
|
||||
iAdrtbMonthName: .int tbMonthName
|
||||
iAdrtbDayName: .int tbDayName
|
||||
iNbSecByDay: .int 3600 * 24
|
||||
/***************************************************/
|
||||
/* ROUTINES INCLUDE */
|
||||
/***************************************************/
|
||||
.include "../affichage.inc"
|
||||
3
Task/Date-format/AWK/date-format.awk
Normal file
3
Task/Date-format/AWK/date-format.awk
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
$ awk 'BEGIN{t=systime();print strftime("%Y-%m-%d",t)"\n"strftime("%A, %B %d, %Y",t)}'
|
||||
2009-05-15
|
||||
Friday, May 15, 2009
|
||||
71
Task/Date-format/Action-/date-format.action
Normal file
71
Task/Date-format/Action-/date-format.action
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
DEFINE PTR="CARD"
|
||||
|
||||
TYPE Date=[
|
||||
INT year
|
||||
BYTE month
|
||||
BYTE day]
|
||||
|
||||
PTR ARRAY DayOfWeeks(7)
|
||||
PTR ARRAY Months(12)
|
||||
|
||||
PROC Init()
|
||||
DayOfWeeks(0)="Sunday" DayOfWeeks(1)="Monday"
|
||||
DayOfWeeks(2)="Tuesday" DayOfWeeks(3)="Wednesday"
|
||||
DayOfWeeks(4)="Thursday" DayOfWeeks(5)="Friday"
|
||||
DayOfWeeks(6)="Saturday"
|
||||
Months(0)="January" Months(1)="February"
|
||||
Months(2)="March" Months(3)="April"
|
||||
Months(4)="May" Months(5)="June"
|
||||
Months(6)="July" Months(7)="August"
|
||||
Months(8)="September" Months(9)="October"
|
||||
Months(10)="November" Months(11)="December"
|
||||
RETURN
|
||||
|
||||
;https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week#Sakamoto.27s_methods
|
||||
BYTE FUNC DayOfWeek(Date POINTER d) ;1<=m<=12, y>1752
|
||||
BYTE ARRAY t=[0 3 2 5 0 3 5 1 4 6 2 4]
|
||||
BYTE res
|
||||
INT y
|
||||
|
||||
y=d.year
|
||||
IF d.month<3 THEN
|
||||
y==-1
|
||||
FI
|
||||
res=(y+y/4-y/100+y/400+t(d.month-1)+d.day) MOD 7
|
||||
RETURN (res)
|
||||
|
||||
PROC PrintB2(BYTE x)
|
||||
IF x<10 THEN
|
||||
Put('0)
|
||||
FI
|
||||
PrintB(x)
|
||||
RETURN
|
||||
|
||||
PROC PrintDateShort(Date POINTER d)
|
||||
PrintI(d.year) Put('-)
|
||||
PrintB2(d.month) Put('-)
|
||||
PrintB2(d.day)
|
||||
RETURN
|
||||
|
||||
PROC PrintDateLong(Date POINTER d)
|
||||
BYTE wd
|
||||
|
||||
wd=DayOfWeek(d)
|
||||
Print(DayOfWeeks(wd)) Print(", ")
|
||||
Print(Months(d.month-1)) Put(' )
|
||||
PrintB(d.day) Print(", ")
|
||||
PrintI(d.year)
|
||||
RETURN
|
||||
|
||||
PROC Main()
|
||||
Date d
|
||||
|
||||
Init()
|
||||
|
||||
;There is no function to get the current date
|
||||
;on Atari 8-bit computer
|
||||
d.year=2021 d.month=9 d.day=1
|
||||
|
||||
PrintDateShort(d) PutE()
|
||||
PrintDateLong(d) PutE()
|
||||
RETURN
|
||||
44
Task/Date-format/Ada/date-format.ada
Normal file
44
Task/Date-format/Ada/date-format.ada
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
with Ada.Calendar; use Ada.Calendar;
|
||||
with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
|
||||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
|
||||
procedure Date_Format is
|
||||
function Image (Month : 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 12 => return "December";
|
||||
end case;
|
||||
end Image;
|
||||
function Image (Day : Day_Name) return String is
|
||||
begin
|
||||
case Day is
|
||||
when Monday => return "Monday";
|
||||
when Tuesday => return "Tuesday";
|
||||
when Wednesday => return "Wednesday";
|
||||
when Thursday => return "Thursday";
|
||||
when Friday => return "Friday";
|
||||
when Saturday => return "Saturday";
|
||||
when Sunday => return "Sunday";
|
||||
end case;
|
||||
end Image;
|
||||
Today : Time := Clock;
|
||||
begin
|
||||
Put_Line (Image (Today) (1..10));
|
||||
Put_Line
|
||||
( Image (Day_Of_Week (Today)) & ", "
|
||||
& Image (Ada.Calendar.Month (Today))
|
||||
& Day_Number'Image (Ada.Calendar.Day (Today)) & ","
|
||||
& Year_Number'Image (Ada.Calendar.Year (Today))
|
||||
);
|
||||
end Date_Format;
|
||||
5
Task/Date-format/Apex/date-format.apex
Normal file
5
Task/Date-format/Apex/date-format.apex
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Datetime dtNow = datetime.now();
|
||||
String strDt1 = dtNow.format('yyyy-MM-dd');
|
||||
String strDt2 = dtNow.format('EEEE, MMMM dd, yyyy');
|
||||
system.debug(strDt1); // "2007-11-10"
|
||||
system.debug(strDt2); //"Sunday, November 10, 2007"
|
||||
6
Task/Date-format/AppleScript/date-format-1.applescript
Normal file
6
Task/Date-format/AppleScript/date-format-1.applescript
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
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
|
||||
set longFormat to (w as text) & (", " & m) & (space & d) & (", " & y)
|
||||
|
||||
return (shortFormat & linefeed & longFormat)
|
||||
2
Task/Date-format/AppleScript/date-format-2.applescript
Normal file
2
Task/Date-format/AppleScript/date-format-2.applescript
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"2020-10-28
|
||||
Wednesday, October 28, 2020"
|
||||
8
Task/Date-format/AppleScript/date-format-3.applescript
Normal file
8
Task/Date-format/AppleScript/date-format-3.applescript
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
tell (the current date)
|
||||
set shortdate to text 1 thru 10 of (it as «class isot» as string)
|
||||
set longdate to the contents of [its weekday, ", ", ¬
|
||||
(its month), " ", day, ", ", year] as text
|
||||
end tell
|
||||
|
||||
log the shortdate
|
||||
log the longdate
|
||||
71
Task/Date-format/AppleScript/date-format-4.applescript
Normal file
71
Task/Date-format/AppleScript/date-format-4.applescript
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
-- iso8601Short :: Date -> String
|
||||
on iso8601Short(dte)
|
||||
text 1 thru 10 of iso8601Local(dte)
|
||||
end iso8601Short
|
||||
|
||||
|
||||
-- longDate :: Date -> String
|
||||
on longDate(dte)
|
||||
tell dte
|
||||
"" & its weekday & ", " & its month & " " & its day & ", " & year
|
||||
end tell
|
||||
end longDate
|
||||
|
||||
|
||||
---------------------------- TEST --------------------------
|
||||
on run
|
||||
|
||||
unlines(apList({iso8601Short, longDate}, ¬
|
||||
{current date}))
|
||||
|
||||
end run
|
||||
|
||||
|
||||
-------------------------- GENERIC -------------------------
|
||||
|
||||
|
||||
-- Each member of a list of functions applied to
|
||||
-- each of a list of arguments, deriving a list of new values
|
||||
-- apList (<*>) :: [(a -> b)] -> [a] -> [b]
|
||||
on apList(fs, xs)
|
||||
set lst to {}
|
||||
repeat with f in fs
|
||||
tell mReturn(contents of f)
|
||||
repeat with x in xs
|
||||
set end of lst to |λ|(contents of x)
|
||||
end repeat
|
||||
end tell
|
||||
end repeat
|
||||
return lst
|
||||
end apList
|
||||
|
||||
|
||||
-- iso8601Local :: Date -> String
|
||||
on iso8601Local(dte)
|
||||
(dte as «class isot» as string)
|
||||
end iso8601Local
|
||||
|
||||
|
||||
-- mReturn :: First-class m => (a -> b) -> m (a -> b)
|
||||
on mReturn(f)
|
||||
-- 2nd class handler function lifted into 1st class script wrapper.
|
||||
if script is class of f then
|
||||
f
|
||||
else
|
||||
script
|
||||
property |λ| : f
|
||||
end script
|
||||
end if
|
||||
end mReturn
|
||||
|
||||
|
||||
-- unlines :: [String] -> String
|
||||
on unlines(xs)
|
||||
-- A single string formed by the intercalation
|
||||
-- of a list of strings with the newline character.
|
||||
set {dlm, my text item delimiters} to ¬
|
||||
{my text item delimiters, linefeed}
|
||||
set s to xs as text
|
||||
set my text item delimiters to dlm
|
||||
s
|
||||
end unlines
|
||||
4
Task/Date-format/Arturo/date-format.arturo
Normal file
4
Task/Date-format/Arturo/date-format.arturo
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
currentTime: now
|
||||
|
||||
print to :string.format: "YYYY-MM-dd" currentTime
|
||||
print to :string.format: "dddd, MMMM dd, YYYY" currentTime
|
||||
3
Task/Date-format/AutoHotkey/date-format.ahk
Normal file
3
Task/Date-format/AutoHotkey/date-format.ahk
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
FormatTime, Date1, , yyyy-MM-dd ; "2007-11-10"
|
||||
FormatTime, Date2, , LongDate ; "Sunday, November 10, 2007"
|
||||
MsgBox %Date1% `n %Date2%
|
||||
31
Task/Date-format/AutoIt/date-format.autoit
Normal file
31
Task/Date-format/AutoIt/date-format.autoit
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#include <Date.au3>
|
||||
|
||||
$iYear = 2007
|
||||
$iMonth = 11
|
||||
$iDay = 10
|
||||
|
||||
ConsoleWrite(StringFormat('%4d-%02d-%02d', $iYear, $iMonth, $iDay) & @LF)
|
||||
|
||||
$iWeekDay = _DateToDayOfWeekISO($iYear, $iMonth, $iDay)
|
||||
ConsoleWrite(StringFormat('%s, %s %02d, %4d', _GetLongDayLocale($iWeekDay), _GetLongMonthLocale($iMonth), $iDay, $iYear) & @LF)
|
||||
|
||||
|
||||
Func _GetLongDayLocale($_iWeekDay) ; 1..7 Monday=1
|
||||
Local $aDayName[8] = [0, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30]
|
||||
Return GetLocaleInfo($aDayName[$_iWeekDay])
|
||||
EndFunc
|
||||
|
||||
Func _GetLongMonthLocale($_iMonth) ; 1..12 January=1
|
||||
Local $aMonthName[13] = [0, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43]
|
||||
Return GetLocaleInfo($aMonthName[$_iMonth])
|
||||
EndFunc
|
||||
|
||||
Func GetLocaleInfo($_LCType)
|
||||
Local $ret, $LCID, $sBuffer, $iLen
|
||||
$ret = DllCall('kernel32', 'long', 'GetSystemDefaultLCID')
|
||||
$LCID = $ret[0]
|
||||
$ret = DllCall('kernel32', 'long', 'GetLocaleInfo', 'long', $LCID, 'long', $_LCType, 'str', $sBuffer, 'long', 0)
|
||||
$iLen = $ret[0]
|
||||
$ret = DllCall('kernel32', 'long', 'GetLocaleInfo', 'long', $LCID, 'long', $_LCType, 'str', $sBuffer, 'long', $iLen)
|
||||
Return $ret[3]
|
||||
EndFunc
|
||||
6
Task/Date-format/BASIC/date-format.basic
Normal file
6
Task/Date-format/BASIC/date-format.basic
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#include "vbcompat.bi"
|
||||
|
||||
DIM today As Double = Now()
|
||||
|
||||
PRINT Format(today, "yyyy-mm-dd")
|
||||
PRINT Format(today, "dddd, mmmm d, yyyy")
|
||||
18
Task/Date-format/BBC-BASIC/date-format.basic
Normal file
18
Task/Date-format/BBC-BASIC/date-format.basic
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
daysow$ = "Sunday Monday Tuesday Wednesday Thursday Friday Saturday"
|
||||
months$ = "January February March April May June " + \
|
||||
\ "July August September October November December"
|
||||
|
||||
date$ = TIME$
|
||||
dayow% = (INSTR(daysow$, MID$(date$,1,3)) + 9) DIV 10
|
||||
month% = (INSTR(months$, MID$(date$,8,3)) + 9) DIV 10
|
||||
|
||||
PRINT MID$(date$,12,4) "-" RIGHT$("0"+STR$month%,2) + "-" + MID$(date$,5,2)
|
||||
|
||||
PRINT FNrtrim(MID$(daysow$, dayow%*10-9, 10)) ", " ;
|
||||
PRINT FNrtrim(MID$(months$, month%*10-9, 10)) " " ;
|
||||
PRINT MID$(date$,5,2) ", " MID$(date$,12,4)
|
||||
END
|
||||
|
||||
DEF FNrtrim(A$)
|
||||
WHILE RIGHT$(A$) = " " A$ = LEFT$(A$) : ENDWHILE
|
||||
= A$
|
||||
4
Task/Date-format/BaCon/date-format.bacon
Normal file
4
Task/Date-format/BaCon/date-format.bacon
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
' Date format
|
||||
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"
|
||||
35
Task/Date-format/Batch-File/date-format.bat
Normal file
35
Task/Date-format/Batch-File/date-format.bat
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
:: Define arrays of days/months we'll need
|
||||
set daynames=Monday Tuesday Wednesday Thursday Friday Saturday Sunday
|
||||
set monthnames=January February March April May June July August September October November December
|
||||
|
||||
:: Separate the output of the 'date /t' command (outputs in the format of "Sun 16/04/2017") into 4 variables
|
||||
for /f "tokens=1,2,3,4 delims=/ " %%i in ('date /t') do (
|
||||
set dayname=%%i
|
||||
set day=%%j
|
||||
set month=%%k
|
||||
set year=%%l
|
||||
)
|
||||
|
||||
:: Crosscheck the first 3 letters of every word in %daynames% to the 3 letter day name found previously
|
||||
for %%i in (%daynames%) do (
|
||||
set tempdayname=%%i
|
||||
set comparedayname=!tempdayname:~0,3!
|
||||
if "%dayname%"=="!comparedayname!" set fulldayname=%%i
|
||||
)
|
||||
|
||||
:: Variables starting with "0" during the 'set /a' command are treated as octal numbers. To avoid this, if the first character of %month% is "0", it is removed
|
||||
if "%month:~0,1%"=="0" set monthtemp=%month:~1,1%
|
||||
set monthcount=0
|
||||
|
||||
:: Iterates through %monthnames% and when it reaches the amount of iterations dictated by %month%, sets %monthname% as the current month being iterated through
|
||||
for %%i in (%monthnames%) do (
|
||||
set /a monthcount+=1
|
||||
if %monthtemp%==!monthcount! set monthname=%%i
|
||||
)
|
||||
|
||||
echo %year%-%month%-%day%
|
||||
echo %fulldayname%, %monthname% %day%, %year%
|
||||
pause>nul
|
||||
5
Task/Date-format/Beads/date-format.beads
Normal file
5
Task/Date-format/Beads/date-format.beads
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
beads 1 program 'Date format'
|
||||
|
||||
calc main_init
|
||||
log time_to_str('[iso date]')
|
||||
log time_to_str('[sunday], [january] [day2], [year]')
|
||||
64
Task/Date-format/C++/date-format.cpp
Normal file
64
Task/Date-format/C++/date-format.cpp
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
// Display the current date in the formats of "2007-11-10"
|
||||
// and "Sunday, November 10, 2007".
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <ctime>
|
||||
|
||||
/** Return the current date in a string, formatted as either ISO-8601
|
||||
* or "Weekday-name, Month-name Day, Year".
|
||||
*
|
||||
* The date is initialized when the object is created and will return
|
||||
* the same date for the lifetime of the object. The date returned
|
||||
* is the date in the local timezone.
|
||||
*/
|
||||
class Date
|
||||
{
|
||||
struct tm ltime;
|
||||
|
||||
public:
|
||||
/// Default constructor.
|
||||
Date()
|
||||
{
|
||||
time_t t = time(0);
|
||||
localtime_r(&t, <ime);
|
||||
}
|
||||
|
||||
/** Return the date based on a format string. The format string is
|
||||
* fed directly into strftime(). See the strftime() documentation
|
||||
* for information on the proper construction of format strings.
|
||||
*
|
||||
* @param[in] fmt is a valid strftime() format string.
|
||||
*
|
||||
* @return a string containing the formatted date, or a blank string
|
||||
* if the format string was invalid or resulted in a string that
|
||||
* exceeded the internal buffer length.
|
||||
*/
|
||||
std::string getDate(const char* fmt)
|
||||
{
|
||||
char out[200];
|
||||
size_t result = strftime(out, sizeof out, fmt, <ime);
|
||||
return std::string(out, out + result);
|
||||
}
|
||||
|
||||
/** Return the date in ISO-8601 date format.
|
||||
*
|
||||
* @return a string containing the date in ISO-8601 date format.
|
||||
*/
|
||||
std::string getISODate() {return getDate("%F");}
|
||||
|
||||
/** Return the date formatted as "Weekday-name, Month-name Day, Year".
|
||||
*
|
||||
* @return a string containing the date in the specified format.
|
||||
*/
|
||||
std::string getTextDate() {return getDate("%A, %B %d, %Y");}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
Date d;
|
||||
std::cout << d.getISODate() << std::endl;
|
||||
std::cout << d.getTextDate() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
14
Task/Date-format/C-sharp/date-format.cs
Normal file
14
Task/Date-format/C-sharp/date-format.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
|
||||
namespace RosettaCode.DateFormat
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
DateTime today = DateTime.Now.Date;
|
||||
Console.WriteLine(today.ToString("yyyy-MM-dd"));
|
||||
Console.WriteLine(today.ToString("dddd, MMMMM d, yyyy"));
|
||||
}
|
||||
}
|
||||
}
|
||||
23
Task/Date-format/C/date-format.c
Normal file
23
Task/Date-format/C/date-format.c
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#define MAX_BUF 50
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char buf[MAX_BUF];
|
||||
time_t seconds = time(NULL);
|
||||
struct tm *now = localtime(&seconds);
|
||||
const char *months[] = {"January", "February", "March", "April", "May", "June",
|
||||
"July", "August", "September", "October", "November", "December"};
|
||||
|
||||
const char *days[] = {"Sunday", "Monday", "Tuesday", "Wednesday","Thursday","Friday","Saturday"};
|
||||
|
||||
(void) printf("%d-%d-%d\n", now->tm_year + 1900, now->tm_mon + 1, now->tm_mday);
|
||||
(void) printf("%s, %s %d, %d\n",days[now->tm_wday], months[now->tm_mon],
|
||||
now->tm_mday, now->tm_year + 1900);
|
||||
/* using the strftime (the result depends on the locale) */
|
||||
(void) strftime(buf, MAX_BUF, "%A, %B %e, %Y", now);
|
||||
(void) printf("%s\n", buf);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
64
Task/Date-format/COBOL/date-format.cobol
Normal file
64
Task/Date-format/COBOL/date-format.cobol
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. Date-Format.
|
||||
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
|
||||
01 Days-Area.
|
||||
03 Days-Data.
|
||||
05 FILLER PIC X(9) VALUE "Monday".
|
||||
05 FILLER PIC X(9) VALUE "Tuesday".
|
||||
05 FILLER PIC X(9) VALUE "Wednesday".
|
||||
05 FILLER PIC X(9) VALUE "Thursday".
|
||||
05 FILLER PIC X(9) VALUE "Friday".
|
||||
05 FILLER PIC X(9) VALUE "Saturday".
|
||||
05 FILLER PIC X(9) VALUE "Sunday".
|
||||
|
||||
03 Days-Values REDEFINES Days-Data.
|
||||
05 Days-Table PIC X(9) OCCURS 7 TIMES.
|
||||
|
||||
01 Months-Area.
|
||||
03 Months-Data.
|
||||
05 FILLER PIC X(9) VALUE "January".
|
||||
05 FILLER PIC X(9) VALUE "February".
|
||||
05 FILLER PIC X(9) VALUE "March".
|
||||
05 FILLER PIC X(9) VALUE "April".
|
||||
05 FILLER PIC X(9) VALUE "May".
|
||||
05 FILLER PIC X(9) VALUE "June".
|
||||
05 FILLER PIC X(9) VALUE "July".
|
||||
05 FILLER PIC X(9) VALUE "August".
|
||||
05 FILLER PIC X(9) VALUE "September".
|
||||
05 FILLER PIC X(9) VALUE "October".
|
||||
05 FILLER PIC X(9) VALUE "November".
|
||||
05 FILLER PIC X(9) VALUE "December".
|
||||
|
||||
03 Months-Values REDEFINES Months-Data.
|
||||
05 Months-Table PIC X(9) OCCURS 12 TIMES.
|
||||
|
||||
01 Current-Date-Str.
|
||||
03 Current-Year PIC X(4).
|
||||
03 Current-Month PIC X(2).
|
||||
03 Current-Day PIC X(2).
|
||||
|
||||
01 Current-Day-Of-Week PIC 9.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
MOVE FUNCTION CURRENT-DATE (1:8) TO Current-Date-Str
|
||||
|
||||
DISPLAY Current-Year "-" Current-Month "-" Current-Day
|
||||
|
||||
ACCEPT Current-Day-Of-Week FROM DAY-OF-WEEK
|
||||
DISPLAY
|
||||
FUNCTION TRIM(
|
||||
Days-Table (FUNCTION NUMVAL(Current-Day-Of-Week)))
|
||||
", "
|
||||
FUNCTION TRIM(
|
||||
Months-Table (FUNCTION NUMVAL(Current-Month)))
|
||||
" "
|
||||
Current-Day
|
||||
", "
|
||||
Current-Year
|
||||
END-DISPLAY
|
||||
|
||||
GOBACK
|
||||
.
|
||||
5
Task/Date-format/Clojure/date-format.clj
Normal file
5
Task/Date-format/Clojure/date-format.clj
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
(let [now (.getTime (java.util.Calendar/getInstance))
|
||||
f1 (java.text.SimpleDateFormat. "yyyy-MM-dd")
|
||||
f2 (java.text.SimpleDateFormat. "EEEE, MMMM dd, yyyy")]
|
||||
(println (.format f1 now))
|
||||
(println (.format f2 now)))
|
||||
13
Task/Date-format/CoffeeScript/date-format-1.coffee
Normal file
13
Task/Date-format/CoffeeScript/date-format-1.coffee
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
date = new Date
|
||||
|
||||
console.log date.toLocaleDateString 'en-GB',
|
||||
month: '2-digit'
|
||||
day: '2-digit'
|
||||
year: 'numeric'
|
||||
.split('/').reverse().join '-'
|
||||
|
||||
console.log date.toLocaleDateString 'en-US',
|
||||
weekday: 'long'
|
||||
month: 'long'
|
||||
day: 'numeric'
|
||||
year: 'numeric'
|
||||
26
Task/Date-format/CoffeeScript/date-format-2.coffee
Normal file
26
Task/Date-format/CoffeeScript/date-format-2.coffee
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# JS does not have extensive formatting support out of the box. This code shows
|
||||
# how you could create a date formatter object.
|
||||
DateFormatter = ->
|
||||
weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
|
||||
months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
|
||||
pad = (n) ->
|
||||
if n < 10
|
||||
"0" + n
|
||||
else
|
||||
n
|
||||
|
||||
brief: (date) ->
|
||||
month = 1 + date.getMonth()
|
||||
"#{date.getFullYear()}-#{pad month}-#{pad date.getDate()}"
|
||||
|
||||
verbose: (date) ->
|
||||
weekday = weekdays[date.getDay()]
|
||||
month = months[date.getMonth()]
|
||||
day = date.getDate()
|
||||
year = date.getFullYear();
|
||||
"#{weekday}, #{month} #{day}, #{year}"
|
||||
|
||||
formatter = DateFormatter()
|
||||
date = new Date()
|
||||
console.log formatter.brief(date)
|
||||
console.log formatter.verbose(date)
|
||||
4
Task/Date-format/ColdFusion/date-format.cfm
Normal file
4
Task/Date-format/ColdFusion/date-format.cfm
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<cfoutput>
|
||||
#dateFormat(Now(), "YYYY-MM-DD")#<br />
|
||||
#dateFormat(Now(), "DDDD, MMMM DD, YYYY")#
|
||||
</cfoutput>
|
||||
10
Task/Date-format/Common-Lisp/date-format-1.lisp
Normal file
10
Task/Date-format/Common-Lisp/date-format-1.lisp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
(defconstant *day-names*
|
||||
#("Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday"))
|
||||
(defconstant *month-names*
|
||||
#(nil "January" "February" "March" "April" "May" "June" "July"
|
||||
"August" "September" "October" "November" "December"))
|
||||
|
||||
(multiple-value-bind (sec min hour date month year day daylight-p zone) (get-decoded-time)
|
||||
(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))
|
||||
4
Task/Date-format/Common-Lisp/date-format-2.lisp
Normal file
4
Task/Date-format/Common-Lisp/date-format-2.lisp
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(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"
|
||||
21
Task/Date-format/Component-Pascal/date-format.pas
Normal file
21
Task/Date-format/Component-Pascal/date-format.pas
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
MODULE DateFormat;
|
||||
IMPORT StdLog, Dates;
|
||||
|
||||
PROCEDURE Do*;
|
||||
VAR
|
||||
d: Dates.Date;
|
||||
resp: ARRAY 64 OF CHAR;
|
||||
BEGIN
|
||||
Dates.GetDate(d);
|
||||
Dates.DateToString(d,Dates.short,resp);
|
||||
StdLog.String(":> " + resp);StdLog.Ln;
|
||||
Dates.DateToString(d,Dates.abbreviated,resp);
|
||||
StdLog.String(":> " + resp);StdLog.Ln;
|
||||
Dates.DateToString(d,Dates.long,resp);
|
||||
StdLog.String(":> " + resp);StdLog.Ln;
|
||||
Dates.DateToString(d,Dates.plainAbbreviated,resp);
|
||||
StdLog.String(":> " + resp);StdLog.Ln;
|
||||
Dates.DateToString(d,Dates.plainLong,resp);
|
||||
StdLog.String(":> " + resp);StdLog.Ln;
|
||||
END Do;
|
||||
END DateFormat.
|
||||
5
Task/Date-format/Crystal/date-format.crystal
Normal file
5
Task/Date-format/Crystal/date-format.crystal
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
require "time"
|
||||
|
||||
time = Time.local
|
||||
puts time.to_s("%Y-%m-%d")
|
||||
puts time.to_s("%A, %B %d, %Y")
|
||||
17
Task/Date-format/D/date-format.d
Normal file
17
Task/Date-format/D/date-format.d
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
module datetimedemo ;
|
||||
|
||||
import tango.time.Time ;
|
||||
import tango.text.locale.Locale ;
|
||||
import tango.time.chrono.Gregorian ;
|
||||
|
||||
import tango.io.Stdout ;
|
||||
|
||||
void main() {
|
||||
Gregorian g = new Gregorian ;
|
||||
Stdout.layout = new Locale; // enable Stdout to handle date/time format
|
||||
Time d = g.toTime(2007, 11, 10, 0, 0, 0, 0, g.AD_ERA) ;
|
||||
Stdout.format("{:yyy-MM-dd}", d).newline ;
|
||||
Stdout.format("{:dddd, MMMM d, yyy}", d).newline ;
|
||||
d = g.toTime(2008, 2, 1, 0, 0, 0, 0, g.AD_ERA) ;
|
||||
Stdout.format("{:dddd, MMMM d, yyy}", d).newline ;
|
||||
}
|
||||
1
Task/Date-format/Delphi/date-format.delphi
Normal file
1
Task/Date-format/Delphi/date-format.delphi
Normal file
|
|
@ -0,0 +1 @@
|
|||
ShowMessage(FormatDateTime('yyyy-mm-dd', Now) +#13#10+ FormatDateTime('dddd, mmmm dd, yyyy', Now));
|
||||
3
Task/Date-format/Diego/date-format.diego
Normal file
3
Task/Date-format/Diego/date-format.diego
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
me_lang(en)_cal(gregorian);
|
||||
me_msg()_now()_format(yyyy-mm-dd);
|
||||
me_msg()_now()_format(eeee, mmmm dd, yyyy);
|
||||
5
Task/Date-format/EGL/date-format.egl
Normal file
5
Task/Date-format/EGL/date-format.egl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
// 2012-09-26
|
||||
SysLib.writeStdout(StrLib.formatDate(DateTimeLib.currentDate(), "yyyy-MM-dd"));
|
||||
// Wednesday, September 26, 2012
|
||||
SysLib.setLocale("en", "US");
|
||||
SysLib.writeStdout(StrLib.formatDate(DateTimeLib.currentDate(), "EEEE, MMMM dd, yyyy"));
|
||||
23
Task/Date-format/Elixir/date-format.elixir
Normal file
23
Task/Date-format/Elixir/date-format.elixir
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
defmodule Date_format do
|
||||
def iso_date, do: Date.utc_today |> Date.to_iso8601
|
||||
|
||||
def iso_date(year, month, day), do: Date.from_erl!({year, month, day}) |> Date.to_iso8601
|
||||
|
||||
def long_date, do: Date.utc_today |> long_date
|
||||
|
||||
def long_date(year, month, day), do: Date.from_erl!({year, month, day}) |> long_date
|
||||
|
||||
@months Enum.zip(1..12, ~w[January February March April May June July August September October November December])
|
||||
|> Map.new
|
||||
@weekdays Enum.zip(1..7, ~w[Monday Tuesday Wednesday Thursday Friday Saturday Sunday])
|
||||
|> Map.new
|
||||
def long_date(date) do
|
||||
weekday = Date.day_of_week(date)
|
||||
"#{@weekdays[weekday]}, #{@months[date.month]} #{date.day}, #{date.year}"
|
||||
end
|
||||
end
|
||||
|
||||
IO.puts Date_format.iso_date
|
||||
IO.puts Date_format.long_date
|
||||
IO.puts Date_format.iso_date(2007,11,10)
|
||||
IO.puts Date_format.long_date(2007,11,10)
|
||||
6
Task/Date-format/Emacs-Lisp/date-format.l
Normal file
6
Task/Date-format/Emacs-Lisp/date-format.l
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(format-time-string "%Y-%m-%d")
|
||||
(format-time-string "%F") ;; new in Emacs 24
|
||||
;; => "2015-11-08"
|
||||
|
||||
(format-time-string "%A, %B %e, %Y")
|
||||
;; => "Sunday, November 8, 2015"
|
||||
24
Task/Date-format/Erlang/date-format.erl
Normal file
24
Task/Date-format/Erlang/date-format.erl
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
-module(format_date).
|
||||
-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(io,[format/2]).
|
||||
-import(lists,[append/1]).
|
||||
|
||||
iso_date() -> iso_date(date()).
|
||||
iso_date(Year, Month, Day) -> iso_date({Year, Month, Day}).
|
||||
iso_date(Date) ->
|
||||
format("~4B-~2..0B-~2..0B~n", tuple_to_list(Date)).
|
||||
|
||||
long_date() -> long_date(date()).
|
||||
long_date(Year, Month, Day) -> long_date({Year, Month, Day}).
|
||||
long_date(Date = {Year, Month, Day}) ->
|
||||
Months = { "January", "February", "March", "April",
|
||||
"May", "June", "July", "August",
|
||||
"September", "October", "November", "December" },
|
||||
Weekdays = { "Monday", "Tuesday", "Wednesday", "Thursday",
|
||||
"Friday", "Saturday", "Sunday" },
|
||||
Weekday = day_of_the_week(Date),
|
||||
WeekdayName = element(Weekday, Weekdays),
|
||||
MonthName = element(Month, Months),
|
||||
append([WeekdayName, ", ", MonthName, " ", integer_to_list(Day), ", ",
|
||||
integer_to_list(Year)]).
|
||||
11
Task/Date-format/Euphoria/date-format.euphoria
Normal file
11
Task/Date-format/Euphoria/date-format.euphoria
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
constant days = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}
|
||||
constant months = {"January","February","March","April","May","June",
|
||||
"July","August","September","October","November","December"}
|
||||
|
||||
sequence now
|
||||
|
||||
now = date()
|
||||
now[1] += 1900
|
||||
|
||||
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]})
|
||||
5
Task/Date-format/F-Sharp/date-format.fs
Normal file
5
Task/Date-format/F-Sharp/date-format.fs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
> open System;;
|
||||
> Console.WriteLine( DateTime.Now.ToString("yyyy-MM-dd") );;
|
||||
2010-08-13
|
||||
> Console.WriteLine( "{0:D}", DateTime.Now );;
|
||||
Friday, August 13, 2010
|
||||
4
Task/Date-format/Factor/date-format.factor
Normal file
4
Task/Date-format/Factor/date-format.factor
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
USING: formatting calendar io ;
|
||||
|
||||
now "%Y-%m-%d" strftime print
|
||||
now "%A, %B %d, %Y" strftime print
|
||||
4
Task/Date-format/Fantom/date-format.fantom
Normal file
4
Task/Date-format/Fantom/date-format.fantom
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
fansh> Date.today.toLocale("YYYY-MM-DD")
|
||||
2011-02-24
|
||||
fansh> Date.today.toLocale("WWWW, MMMM DD, YYYY")
|
||||
Thursday, February 24, 2011
|
||||
55
Task/Date-format/Forth/date-format-1.fth
Normal file
55
Task/Date-format/Forth/date-format-1.fth
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
: .-0 ( n -- n )
|
||||
[char] - emit
|
||||
dup 10 < if [char] 0 emit then ;
|
||||
|
||||
: .short-date
|
||||
time&date ( s m h D M Y )
|
||||
1 u.r .-0 1 u.r .-0 1 u.r
|
||||
drop drop drop ;
|
||||
|
||||
: str-table
|
||||
create ( n -- ) 0 do , loop
|
||||
does> ( n -- str len ) swap cells + @ count ;
|
||||
|
||||
here ," December"
|
||||
here ," November"
|
||||
here ," October"
|
||||
here ," September"
|
||||
here ," August"
|
||||
here ," July"
|
||||
here ," June"
|
||||
here ," May"
|
||||
here ," April"
|
||||
here ," March"
|
||||
here ," February"
|
||||
here ," January"
|
||||
12 str-table months
|
||||
|
||||
here ," Sunday"
|
||||
here ," Saturday"
|
||||
here ," Friday"
|
||||
here ," Thursday"
|
||||
here ," Wednesday"
|
||||
here ," Tuesday"
|
||||
here ," Monday"
|
||||
7 str-table weekdays
|
||||
|
||||
\ Zeller's Congruence
|
||||
: zeller ( m -- days since March 1 )
|
||||
9 + 12 mod 1- 26 10 */ 3 + ;
|
||||
|
||||
: weekday ( d m y -- 0..6 ) \ Monday..Sunday
|
||||
over 3 < if 1- then
|
||||
dup 4 /
|
||||
over 100 / -
|
||||
over 400 / + +
|
||||
swap zeller + +
|
||||
1+ 7 mod ;
|
||||
|
||||
: 3dup dup 2over rot ;
|
||||
|
||||
: .long-date
|
||||
time&date ( s m h D M Y )
|
||||
3dup weekday weekdays type ." , "
|
||||
>R 1- months type space 1 u.r ." , " R> .
|
||||
drop drop drop ;
|
||||
61
Task/Date-format/Forth/date-format-2.fth
Normal file
61
Task/Date-format/Forth/date-format-2.fth
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
\ Build up a "language" for date formatting
|
||||
|
||||
\ utility words
|
||||
: UNDER+ ( a b c -- a+c b ) ROT + SWAP ;
|
||||
: 3DUP ( a b c -- a b c a b c ) 2 PICK 2 PICK 2 PICK ;
|
||||
: WRITE$ ( caddr -- ) COUNT TYPE ; \ print a counted string
|
||||
: ',' ( -- ) ." , " ;
|
||||
: '-' ( -- ) ." -" ;
|
||||
|
||||
\ day of week calculation
|
||||
\ "This is an algorithm I've carried with me for 35 years,
|
||||
\ originally in Assembler and Fortran II."
|
||||
\ It counts the number of days from March 1, 1900."
|
||||
\ Wil Baden R.I.P.
|
||||
\ *****************************************************
|
||||
\ **WARNING** only good until 2078 on 16 bit machine **
|
||||
\ *****************************************************
|
||||
DECIMAL
|
||||
: CDAY ( dd mm yyyy -- century_day )
|
||||
-3 UNDER+ OVER 0<
|
||||
IF 12 UNDER+ 1- THEN
|
||||
1900 - 1461 4 */ SWAP 306 * 5 + 10 / + + ;
|
||||
|
||||
: DOW ( cday -- day_of_week ) 2 + 7 MOD 1+ ; ( 7 is Sunday)
|
||||
|
||||
\ formatted number printers
|
||||
: ##. ( n -- ) 0 <# # # #> TYPE ;
|
||||
: ####. ( n -- ) 0 <# # # # # #> TYPE ;
|
||||
|
||||
\ make some string list words
|
||||
: LIST[ ( -- ) !CSP 0 C, ; \ list starts with 0 bytes, record stack pos.
|
||||
: ]LIST ( -- ) 0 C, ALIGN ?CSP ; \ '0' ends list, check stack
|
||||
|
||||
: NEXT$ ( $[1] -- $[2] ) COUNT + ; \ get next string
|
||||
: NTH$ ( n list -- $addr ) SWAP 0 DO NEXT$ LOOP ; \ get nth string
|
||||
|
||||
: " ( -- ) [CHAR] " WORD C@ CHAR+ ALLOT ; \ compile text upto "
|
||||
|
||||
\ make the lists
|
||||
CREATE MONTHS
|
||||
LIST[ " January" " February" " March" " April" " May" " June" " July"
|
||||
" August" " September" " October" " November" " December" ]LIST
|
||||
|
||||
CREATE DAYS
|
||||
LIST[ " Monday" " Tuesday" " Wednesday" " Thursday"
|
||||
" Friday" " Saturday" " Sunday" ]LIST
|
||||
|
||||
\ expose lists as indexable arrays that print the string
|
||||
: ]MONTH$. ( n -- ) MONTHS NTH$ WRITE$ ;
|
||||
: ]DAY$. ( n -- ) DAYS NTH$ WRITE$ ;
|
||||
|
||||
|
||||
\ ===========================================
|
||||
\ Rosetta Task Code Begins
|
||||
|
||||
\ Rosetta Date Format 1
|
||||
: Y-M-D. ( d m y -- ) ####. '-' ##. '-' ##. ;
|
||||
|
||||
\ Rosetta Date Format 2
|
||||
: LONG.DATE ( d m y -- )
|
||||
3DUP CDAY DOW ]DAY$. ',' -ROT ]MONTH$. SPACE ##. ',' ####. ;
|
||||
3
Task/Date-format/Forth/date-format-3.fth
Normal file
3
Task/Date-format/Forth/date-format-3.fth
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
5 7 2018 Y-M-D. 2018-07-05 ok
|
||||
ok
|
||||
5 7 2018 LONG.DATE Thursday, July 05, 2018 ok
|
||||
69
Task/Date-format/Fortran/date-format.f
Normal file
69
Task/Date-format/Fortran/date-format.f
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
PROGRAM DATE
|
||||
|
||||
IMPLICIT NONE
|
||||
|
||||
INTEGER :: dateinfo(8), day
|
||||
CHARACTER(9) :: month, dayname
|
||||
|
||||
CALL DATE_AND_TIME(VALUES=dateinfo)
|
||||
SELECT CASE(dateinfo(2))
|
||||
CASE(1)
|
||||
month = "January"
|
||||
CASE(2)
|
||||
month = "February"
|
||||
CASE(3)
|
||||
month = "March"
|
||||
CASE(4)
|
||||
month = "April"
|
||||
CASE(5)
|
||||
month = "May"
|
||||
CASE(6)
|
||||
month = "June"
|
||||
CASE(7)
|
||||
month = "July"
|
||||
CASE(8)
|
||||
month = "August"
|
||||
CASE(9)
|
||||
month = "September"
|
||||
CASE(10)
|
||||
month = "October"
|
||||
CASE(11)
|
||||
month = "November"
|
||||
CASE(12)
|
||||
month = "December"
|
||||
END SELECT
|
||||
|
||||
day = Day_of_week(dateinfo(3), dateinfo(2), dateinfo(1))
|
||||
|
||||
SELECT CASE(day)
|
||||
CASE(0)
|
||||
dayname = "Saturday"
|
||||
CASE(1)
|
||||
dayname = "Sunday"
|
||||
CASE(2)
|
||||
dayname = "Monday"
|
||||
CASE(3)
|
||||
dayname = "Tuesday"
|
||||
CASE(4)
|
||||
dayname = "Wednesday"
|
||||
CASE(5)
|
||||
dayname = "Thursday"
|
||||
CASE(6)
|
||||
dayname = "Friday"
|
||||
END SELECT
|
||||
|
||||
WRITE(*,"(I0,A,I0,A,I0)") dateinfo(1),"-", dateinfo(2),"-", dateinfo(3)
|
||||
WRITE(*,"(4(A),I0,A,I0)") trim(dayname), ", ", trim(month), " ", dateinfo(3), ", ", dateinfo(1)
|
||||
|
||||
CONTAINS
|
||||
|
||||
FUNCTION Day_of_week(d, m, y)
|
||||
INTEGER :: Day_of_week, j, k
|
||||
INTEGER, INTENT(IN) :: d, m, y
|
||||
|
||||
j = y / 100
|
||||
k = MOD(y, 100)
|
||||
Day_of_week = MOD(d + (m+1)*26/10 + k + k/4 + j/4 + 5*j, 7)
|
||||
END FUNCTION Day_of_week
|
||||
|
||||
END PROGRAM DATE
|
||||
6
Task/Date-format/Free-Pascal/date-format.pas
Normal file
6
Task/Date-format/Free-Pascal/date-format.pas
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
program Format_Date_Time;
|
||||
uses
|
||||
SysUtils;
|
||||
begin
|
||||
WriteLn(FormatDateTime('yyyy-mm-dd', Now) +#13#10+ FormatDateTime('dddd, mmmm dd, yyyy', Now));
|
||||
end.
|
||||
10
Task/Date-format/FreeBASIC/date-format.basic
Normal file
10
Task/Date-format/FreeBASIC/date-format.basic
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
#Include "vbcompat.bi"
|
||||
|
||||
Dim d As Long = Now
|
||||
Print "This example was created on : "; Format(d, "yyyy-mm-dd")
|
||||
Print "In other words on : "; Format(d, "dddd, mmmm d, yyyy")
|
||||
Print
|
||||
Print "Press any key to quit the program"
|
||||
Sleep
|
||||
2
Task/Date-format/Frink/date-format.frink
Normal file
2
Task/Date-format/Frink/date-format.frink
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
println[now[] -> ### yyyy-MM-dd ###]
|
||||
println[now[] -> ### EEEE, MMMM d, yyyy ###]
|
||||
2
Task/Date-format/FunL/date-format.funl
Normal file
2
Task/Date-format/FunL/date-format.funl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
println( format('%tF', $date) )
|
||||
println( format('%1$tA, %1$tB %1$td, %1$tY', $date) )
|
||||
6
Task/Date-format/FutureBasic/date-format.basic
Normal file
6
Task/Date-format/FutureBasic/date-format.basic
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
window 1
|
||||
|
||||
print date(@"yyyy-MM-dd")
|
||||
print date(@"EEEE, MMMM dd, yyyy")
|
||||
|
||||
HandleEvents
|
||||
6
Task/Date-format/Gambas/date-format.gambas
Normal file
6
Task/Date-format/Gambas/date-format.gambas
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
Public Sub Main()
|
||||
|
||||
Print Format(Now, "yyyy - mm - dd")
|
||||
Print Format(Now, "dddd, mmmm dd, yyyy")
|
||||
|
||||
End
|
||||
9
Task/Date-format/Go/date-format.go
Normal file
9
Task/Date-format/Go/date-format.go
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
package main
|
||||
|
||||
import "time"
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println(time.Now().Format("2006-01-02"))
|
||||
fmt.Println(time.Now().Format("Monday, January 2, 2006"))
|
||||
}
|
||||
2
Task/Date-format/Groovy/date-format-1.groovy
Normal file
2
Task/Date-format/Groovy/date-format-1.groovy
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
def isoFormat = { date -> date.format("yyyy-MM-dd") }
|
||||
def longFormat = { date -> date.format("EEEE, MMMM dd, yyyy") }
|
||||
3
Task/Date-format/Groovy/date-format-2.groovy
Normal file
3
Task/Date-format/Groovy/date-format-2.groovy
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
def now = new Date()
|
||||
println isoFormat(now)
|
||||
println longFormat(now)
|
||||
11
Task/Date-format/Haskell/date-format.hs
Normal file
11
Task/Date-format/Haskell/date-format.hs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import Data.Time
|
||||
(FormatTime, formatTime, defaultTimeLocale, utcToLocalTime,
|
||||
getCurrentTimeZone, getCurrentTime)
|
||||
|
||||
formats :: FormatTime t => [t -> String]
|
||||
formats = (formatTime defaultTimeLocale) <$> ["%F", "%A, %B %d, %Y"]
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
t <- pure utcToLocalTime <*> getCurrentTimeZone <*> getCurrentTime
|
||||
putStrLn $ unlines (formats <*> pure t)
|
||||
13
Task/Date-format/HicEst/date-format.hicest
Normal file
13
Task/Date-format/HicEst/date-format.hicest
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
CHARACTER string*40
|
||||
|
||||
WRITE(Text=string, Format='UCCYY-MM-DD') 0 ! string: 2010-03-13
|
||||
|
||||
! the U-format to write date and time uses ',' to separate additional output formats
|
||||
! we therefore use ';' in this example and change it to ',' below:
|
||||
WRITE(Text=string,Format='UWWWWWWWWW; MM DD; CCYY') 0 ! string = "Saturday ; 03 13; 2010"
|
||||
READ(Text=string) month ! first numeric value = 3 (no literal month name available)
|
||||
EDIT(Text='January,February,March,April,May,June,July,August,September,October,November,December', ITeM=month, Parse=cMonth) ! cMonth = "March"
|
||||
! change now string = "Saturday ; 03 13; 2010" to "Saturday, March 13, 2010":
|
||||
EDIT(Text=string, Right=' ', Mark1, Right=';', Right=3, Mark2, Delete, Insert=', '//cMonth, Right=';', RePLaceby=',')
|
||||
|
||||
END
|
||||
4
Task/Date-format/Icon/date-format.icon
Normal file
4
Task/Date-format/Icon/date-format.icon
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
procedure main()
|
||||
write(map(&date,"/","-"))
|
||||
write(&dateline ? tab(find(&date[1:5])+4))
|
||||
end
|
||||
2
Task/Date-format/J/date-format-1.j
Normal file
2
Task/Date-format/J/date-format-1.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
6!:0 'YYYY-MM-DD'
|
||||
2010-08-19
|
||||
6
Task/Date-format/J/date-format-2.j
Normal file
6
Task/Date-format/J/date-format-2.j
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
require 'dates system/packages/misc/datefmt.ijs'
|
||||
days=:;:'Sunday Monday Tuesday Wednesday Thursday Friday Saturday'
|
||||
fmtDate=: [:((days ;@{~ weekday),', ',ms0) 3 {.]
|
||||
|
||||
fmtDate 6!:0 ''
|
||||
Thursday, August 19, 2010
|
||||
5
Task/Date-format/Java/date-format-1.java
Normal file
5
Task/Date-format/Java/date-format-1.java
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
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);
|
||||
}
|
||||
18
Task/Date-format/Java/date-format-2.java
Normal file
18
Task/Date-format/Java/date-format-2.java
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.text.DateFormatSymbols;
|
||||
import java.text.DateFormat;
|
||||
public class Dates{
|
||||
public static void main(String[] args){
|
||||
Calendar now = new GregorianCalendar(); //months are 0 indexed, dates are 1 indexed
|
||||
DateFormatSymbols symbols = new DateFormatSymbols(); //names for our months and weekdays
|
||||
|
||||
//plain numbers way
|
||||
System.out.println(now.get(Calendar.YEAR) + "-" + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE));
|
||||
|
||||
//words way
|
||||
System.out.print(symbols.getWeekdays()[now.get(Calendar.DAY_OF_WEEK)] + ", ");
|
||||
System.out.print(symbols.getMonths()[now.get(Calendar.MONTH)] + " ");
|
||||
System.out.println(now.get(Calendar.DATE) + ", " + now.get(Calendar.YEAR));
|
||||
}
|
||||
}
|
||||
13
Task/Date-format/Java/date-format-3.java
Normal file
13
Task/Date-format/Java/date-format-3.java
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
public class Dates
|
||||
{
|
||||
public static void main(final String[] args)
|
||||
{
|
||||
//using DateTimeFormatter
|
||||
LocalDate date = LocalDate.now();
|
||||
DateTimeFormatter dtFormatter = DateTimeFormatter.ofPattern("yyyy MM dd");
|
||||
|
||||
System.out.println(dtFormatter.format(date));
|
||||
}
|
||||
}
|
||||
11
Task/Date-format/Java/date-format-4.java
Normal file
11
Task/Date-format/Java/date-format-4.java
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class DateFormat {
|
||||
public static void main(String[]args){
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
SimpleDateFormat formatLong = new SimpleDateFormat("EEEE, MMMM dd, yyyy");
|
||||
System.out.println(format.format(new Date()));
|
||||
System.out.println(formatLong.format(new Date()));
|
||||
}
|
||||
}
|
||||
7
Task/Date-format/JavaScript/date-format.js
Normal file
7
Task/Date-format/JavaScript/date-format.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
var now = new Date(),
|
||||
weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
|
||||
months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
||||
fmt1 = now.getFullYear() + '-' + (1 + now.getMonth()) + '-' + now.getDate(),
|
||||
fmt2 = weekdays[now.getDay()] + ', ' + months[now.getMonth()] + ' ' + now.getDate() + ', ' + now.getFullYear();
|
||||
console.log(fmt1);
|
||||
console.log(fmt2);
|
||||
9
Task/Date-format/Joy/date-format.joy
Normal file
9
Task/Date-format/Joy/date-format.joy
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
DEFINE weekdays == ["Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday"];
|
||||
months == ["January" "February" "March" "April" "May" "June" "July" "August"
|
||||
"September" "October" "November" "December" ].
|
||||
|
||||
time localtime [[0 at 'd 4 4 format] ["-"] [1 at 'd 2 2 format] ["-"] [2 at 'd 2 2 format]]
|
||||
[i] map [putchars] step '\n putch pop.
|
||||
|
||||
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.
|
||||
3
Task/Date-format/Jq/date-format.jq
Normal file
3
Task/Date-format/Jq/date-format.jq
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
$ jq -n 'now | (strftime("%Y-%m-%d"), strftime("%A, %B %d, %Y"))'
|
||||
"2015-07-02"
|
||||
"Thursday, July 02, 2015"
|
||||
5
Task/Date-format/Julia/date-format.julia
Normal file
5
Task/Date-format/Julia/date-format.julia
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
ts = Dates.today()
|
||||
|
||||
println("Today's date is:")
|
||||
println("\t$ts")
|
||||
println("\t", Dates.format(ts, "E, U dd, yyyy"))
|
||||
9
Task/Date-format/Kotlin/date-format.kotlin
Normal file
9
Task/Date-format/Kotlin/date-format.kotlin
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// version 1.0.6
|
||||
|
||||
import java.util.GregorianCalendar
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val now = GregorianCalendar()
|
||||
println("%tF".format(now))
|
||||
println("%tA, %1\$tB %1\$te, %1\$tY".format(now))
|
||||
}
|
||||
5
Task/Date-format/Langur/date-format-1.langur
Normal file
5
Task/Date-format/Langur/date-format-1.langur
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
var .now = dt//
|
||||
var .format1 = "2006-01-02"
|
||||
var .format2 = "Monday, January 2, 2006"
|
||||
writeln $"\.now:dt.format1;"
|
||||
writeln $"\.now:dt.format2;"
|
||||
3
Task/Date-format/Langur/date-format-2.langur
Normal file
3
Task/Date-format/Langur/date-format-2.langur
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
var .now = dt//
|
||||
writeln $"\.now:dt(2006-01-02);"
|
||||
writeln $"\.now:dt(Monday, January 2, 2006);"
|
||||
2
Task/Date-format/Langur/date-format-3.langur
Normal file
2
Task/Date-format/Langur/date-format-3.langur
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
writeln toString dt//, "2006-01-02"
|
||||
writeln toString dt//, "Monday, January 2, 2006"
|
||||
2
Task/Date-format/Lasso/date-format.lasso
Normal file
2
Task/Date-format/Lasso/date-format.lasso
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
date('11/10/2007')->format('%Q') // 2007-11-10
|
||||
date('11/10/2007')->format('EEEE, MMMM d, YYYY') //Saturday, November 10, 2007
|
||||
23
Task/Date-format/Liberty-BASIC/date-format.basic
Normal file
23
Task/Date-format/Liberty-BASIC/date-format.basic
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
'Display the current date in the formats of "2007-11-10"
|
||||
d$=date$("yyyy/mm/dd")
|
||||
print word$(d$,1,"/")+"-"+word$(d$,2,"/")+"-"+word$(d$,3,"/")
|
||||
|
||||
'and "Sunday, November 10, 2007".
|
||||
day$(0)="Tuesday"
|
||||
day$(1)="Wednesday"
|
||||
day$(2)="Thursday"
|
||||
day$(3)="Friday"
|
||||
day$(4)="Saturday"
|
||||
day$(5)="Sunday"
|
||||
day$(6)="Monday"
|
||||
theDay = date$("days") mod 7
|
||||
print day$(theDay);", ";date$()
|
||||
|
||||
' month in full
|
||||
year=val(word$(d$,1,"/"))
|
||||
month=val(word$(d$,2,"/"))
|
||||
day=val(word$(d$,3,"/"))
|
||||
weekDay$="Tuesday Wednesday Thursday Friday Saturday Sunday Monday"
|
||||
monthLong$="January February March April May June July August September October November December"
|
||||
|
||||
print word$(weekDay$,theDay+1);", ";word$(monthLong$,month);" ";day;", ";year
|
||||
6
Task/Date-format/LiveCode/date-format.livecode
Normal file
6
Task/Date-format/LiveCode/date-format.livecode
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
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
|
||||
2
Task/Date-format/Logo/date-format.logo
Normal file
2
Task/Date-format/Logo/date-format.logo
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
print first shell [date +%F]
|
||||
print first shell [date +"%A, %B %d, %Y"]
|
||||
2
Task/Date-format/Lua/date-format.lua
Normal file
2
Task/Date-format/Lua/date-format.lua
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
print( os.date( "%Y-%m-%d" ) )
|
||||
print( os.date( "%A, %B %d, %Y" ) )
|
||||
2
Task/Date-format/M2000-Interpreter/date-format.m2000
Normal file
2
Task/Date-format/M2000-Interpreter/date-format.m2000
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
Print str$(today, "yyyy-mm-dd")
|
||||
Print str$(today, "dddd, mmm, dd, yyyy")
|
||||
11
Task/Date-format/MATLAB/date-format.m
Normal file
11
Task/Date-format/MATLAB/date-format.m
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
>> datestr(now,'yyyy-mm-dd')
|
||||
|
||||
ans =
|
||||
|
||||
2010-06-18
|
||||
|
||||
>> datestr(now,'dddd, mmmm dd, yyyy')
|
||||
|
||||
ans =
|
||||
|
||||
Friday, June 18, 2010
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
echo -ag $time(yyyy-mm-dd)
|
||||
echo -ag $time(dddd $+ $chr(44) mmmm dd $+ $chr(44) yyyy)
|
||||
4
Task/Date-format/MUMPS/date-format-1.mumps
Normal file
4
Task/Date-format/MUMPS/date-format-1.mumps
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
DTZ
|
||||
WRITE !,"Date format 3: ",$ZDATE($H,3)
|
||||
WRITE !,"Or ",$ZDATE($H,12),", ",$ZDATE($H,9)
|
||||
QUIT
|
||||
21
Task/Date-format/MUMPS/date-format-2.mumps
Normal file
21
Task/Date-format/MUMPS/date-format-2.mumps
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
DTM(H)
|
||||
;You can pass an integer, but the default is to use today's value
|
||||
SET:$DATA(H)=0 H=$HOROLOG
|
||||
NEW Y,YR,RD,MC,MO,DA,MN,DN,DOW
|
||||
SET MN="January,February,March,April,May,June,July,August,September,October,November,December"
|
||||
SET DN="Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday"
|
||||
SET MC="31,28,31,30,31,30,31,31,30,31,30,31"
|
||||
SET Y=+H\365.25 ;This shouldn't be an approximation in production code
|
||||
SET YR=Y+1841 ;Y is the offset from the epoch in years
|
||||
SET RD=((+H-(Y*365.25))+1)\1 ;How far are we into the year?
|
||||
SET $P(MC,",",2)=$S(((YR#4=0)&(YR#100'=0))!((YR#100=0)&(YR#400=0))=0:28,1:29) ;leap year correction
|
||||
SET MO=1,RE=RD FOR QUIT:RE<=$P(MC,",",MO) SET RE=RE-$P(MC,",",MO),MO=MO+1
|
||||
SET DA=RE+1
|
||||
SET DOW=(H#7)+5 ;Fencepost issue - the first piece is 1
|
||||
;add padding as needed
|
||||
SET:$L(MO)<2 MO="0"_MO
|
||||
SET:$L(DA)<2 DA="0"_DA
|
||||
WRITE !,YR,"-",MO,"-",DA
|
||||
WRITE !,$P(DN,",",DOW),", ",$P(MN,",",MO)," ",DA,", ",YR
|
||||
KILL Y,YR,RD,MC,MO,DA,MN,DN,DOW
|
||||
QUIT
|
||||
3
Task/Date-format/Maple/date-format.maple
Normal file
3
Task/Date-format/Maple/date-format.maple
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
with(StringTools);
|
||||
FormatTime("%Y-%m-%d")
|
||||
FormatTime("%A,%B %d, %y")
|
||||
2
Task/Date-format/Mathematica/date-format.math
Normal file
2
Task/Date-format/Mathematica/date-format.math
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
DateString[{"Year", "-", "Month", "-", "Day"}]
|
||||
DateString[{"DayName", ", ", "MonthName", " ", "Day", ", ", "Year"}]
|
||||
1
Task/Date-format/Min/date-format.min
Normal file
1
Task/Date-format/Min/date-format.min
Normal file
|
|
@ -0,0 +1 @@
|
|||
("YYYY-MM-dd" "dddd, MMMM dd, YYYY") ('timestamp dip tformat puts!) foreach
|
||||
5
Task/Date-format/Nanoquery/date-format.nanoquery
Normal file
5
Task/Date-format/Nanoquery/date-format.nanoquery
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import Nanoquery.Util
|
||||
|
||||
d = new(Date)
|
||||
println d.getYear() + "-" + d.getMonth() + "-" + d.getDay()
|
||||
println d.getDayOfWeek() + ", " + d.getMonthName() + " " + d.getDay() + ", " + d.getYear()
|
||||
14
Task/Date-format/Neko/date-format.neko
Normal file
14
Task/Date-format/Neko/date-format.neko
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
/**
|
||||
<doc>
|
||||
<h2>Date format</h2>
|
||||
<p>Neko uses Int32 to store system date/time values.
|
||||
And lib C strftime style formatting for converting to string form</p>
|
||||
</doc>
|
||||
*/
|
||||
|
||||
var date_now = $loader.loadprim("std@date_now", 0)
|
||||
var date_format = $loader.loadprim("std@date_format", 2)
|
||||
|
||||
var now = date_now()
|
||||
$print(date_format(now, "%F"), "\n")
|
||||
$print(date_format(now, "%A, %B %d, %Y"), "\n")
|
||||
3
Task/Date-format/NetRexx/date-format.netrexx
Normal file
3
Task/Date-format/NetRexx/date-format.netrexx
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import java.text.SimpleDateFormat
|
||||
say SimpleDateFormat("yyyy-MM-dd").format(Date())
|
||||
say SimpleDateFormat("EEEE, MMMM dd, yyyy").format(Date())
|
||||
34
Task/Date-format/NewLISP/date-format.l
Normal file
34
Task/Date-format/NewLISP/date-format.l
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
; file: date-format.lsp
|
||||
; url: http://rosettacode.org/wiki/Date_format
|
||||
; author: oofoe 2012-02-01
|
||||
|
||||
; The "now" function returns the current time as a list. A time zone
|
||||
; offset in minutes can be supplied. The example below is for Eastern
|
||||
; Standard Time. NewLISP's implicit list indexing is used to extract
|
||||
; the first three elements of the returned list (year, month and day).
|
||||
|
||||
(setq n (now (* -5 60)))
|
||||
(println "short: " (format "%04d-%02d-%02d" (n 0) (n 1) (n 2)))
|
||||
|
||||
; The "date-value" function returns the time in seconds from the epoch
|
||||
; when used without arguments. The "date" function converts the
|
||||
; seconds into a time representation specified by the format string at
|
||||
; the end. The offset argument ("0" in this example) specifies a
|
||||
; time-zone offset in minutes.
|
||||
|
||||
(println "short: " (date (date-value) 0 "%Y-%m-%d"))
|
||||
|
||||
; The time formatting is supplied by the underlying C library, so
|
||||
; there may be differences on certain platforms. Particularly, leading
|
||||
; zeroes in day numbers can be suppressed with "%-d" on Linux and
|
||||
; FreeBSD, "%e" on OpenBSD, SunOS/Solaris and Mac OS X. Use "%#d" for
|
||||
; Windows.
|
||||
|
||||
(println "long: " (date (date-value) 0 "%A, %B %#d, %Y"))
|
||||
|
||||
; By setting the locale, the date will be displayed appropriately:
|
||||
|
||||
(set-locale "japanese")
|
||||
(println "long: " (date (date-value) 0 "%A, %B %#d, %Y"))
|
||||
|
||||
(exit)
|
||||
5
Task/Date-format/Nim/date-format.nim
Normal file
5
Task/Date-format/Nim/date-format.nim
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import times
|
||||
|
||||
var t = now()
|
||||
echo(t.format("yyyy-MM-dd"))
|
||||
echo(t.format("dddd',' MMMM d',' yyyy"))
|
||||
13
Task/Date-format/OCaml/date-format-1.ocaml
Normal file
13
Task/Date-format/OCaml/date-format-1.ocaml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# #load "unix.cma";;
|
||||
# open Unix;;
|
||||
|
||||
# let t = time() ;;
|
||||
val t : float = 1219997516.
|
||||
|
||||
# let gmt = gmtime t ;;
|
||||
val gmt : Unix.tm =
|
||||
{tm_sec = 56; tm_min = 11; tm_hour = 8; tm_mday = 29; tm_mon = 7;
|
||||
tm_year = 108; tm_wday = 5; tm_yday = 241; tm_isdst = false}
|
||||
|
||||
# Printf.sprintf "%d-%02d-%02d" (1900 + gmt.tm_year) (1 + gmt.tm_mon) gmt.tm_mday ;;
|
||||
- : string = "2008-08-29"
|
||||
12
Task/Date-format/OCaml/date-format-2.ocaml
Normal file
12
Task/Date-format/OCaml/date-format-2.ocaml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
let months = [| "January"; "February"; "March"; "April"; "May"; "June";
|
||||
"July"; "August"; "September"; "October"; "November"; "December" |]
|
||||
|
||||
let days = [| "Sunday"; "Monday"; "Tuesday"; (* Sunday is 0 *)
|
||||
"Wednesday"; "Thursday"; "Friday"; "Saturday" |]
|
||||
|
||||
# Printf.sprintf "%s, %s %d, %d"
|
||||
days.(gmt.tm_wday)
|
||||
months.(gmt.tm_mon)
|
||||
gmt.tm_mday
|
||||
(1900 + gmt.tm_year) ;;
|
||||
- : string = "Friday, August 29, 2008"
|
||||
15
Task/Date-format/Objeck/date-format.objeck
Normal file
15
Task/Date-format/Objeck/date-format.objeck
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
use IO;
|
||||
use Time;
|
||||
|
||||
bundle Default {
|
||||
class CurrentDate {
|
||||
function : Main(args : String[]) ~ Nil {
|
||||
t := Date->New();
|
||||
Console->Print(t->GetYear())->Print("-")->Print(t->GetMonth())->Print("-")
|
||||
->PrintLine(t->GetDay());
|
||||
Console->Print(t->GetDayName())->Print(", ")->Print(t->GetMonthName())
|
||||
->Print(" ")->Print(t->GetDay())->Print(", ")
|
||||
->PrintLine(t->GetYear());
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Task/Date-format/Objective-C/date-format-1.m
Normal file
3
Task/Date-format/Objective-C/date-format-1.m
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
NSLog(@"%@", [NSDate date]);
|
||||
NSLog(@"%@", [[NSDate date] descriptionWithCalendarFormat:@"%Y-%m-%d" timeZone:nil locale:nil]);
|
||||
NSLog(@"%@", [[NSDate date] descriptionWithCalendarFormat:@"%A, %B %d, %Y" timeZone:nil locale:nil]);
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue