CDE
This commit is contained in:
parent
518da4a923
commit
764da6cbbb
6144 changed files with 83610 additions and 11 deletions
1
Task/Date-format/0DESCRIPTION
Normal file
1
Task/Date-format/0DESCRIPTION
Normal file
|
|
@ -0,0 +1 @@
|
|||
{{Clarified-review}}Display the current date in the formats of "2007-11-10" and "Sunday, November 10, 2007".
|
||||
2
Task/Date-format/1META.yaml
Normal file
2
Task/Date-format/1META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
note: Text processing
|
||||
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$))
|
||||
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
|
||||
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;
|
||||
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%
|
||||
6
Task/Date-format/BASIC/date-format.bas
Normal file
6
Task/Date-format/BASIC/date-format.bas
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.bbc
Normal file
18
Task/Date-format/BBC-BASIC/date-format.bbc
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$
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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)))
|
||||
26
Task/Date-format/CoffeeScript/date-format-1.coffee
Normal file
26
Task/Date-format/CoffeeScript/date-format-1.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)
|
||||
3
Task/Date-format/CoffeeScript/date-format-2.coffee
Normal file
3
Task/Date-format/CoffeeScript/date-format-2.coffee
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
> coffee date_format.coffee
|
||||
2012-01-14
|
||||
Saturday, January 14, 2012
|
||||
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.lisp
Normal file
10
Task/Date-format/Common-Lisp/date-format.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))
|
||||
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));
|
||||
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"));
|
||||
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]})
|
||||
55
Task/Date-format/Forth/date-format.fth
Normal file
55
Task/Date-format/Forth/date-format.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 ;
|
||||
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
|
||||
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"))
|
||||
}
|
||||
13
Task/Date-format/Haskell/date-format.hs
Normal file
13
Task/Date-format/Haskell/date-format.hs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import Control.Monad
|
||||
import Data.Time
|
||||
import System.Locale
|
||||
|
||||
format1 :: FormatTime t => t -> String
|
||||
format1 = formatTime defaultTimeLocale "%Y-%m-%e"
|
||||
|
||||
format2 :: FormatTime t => t -> String
|
||||
format2 = formatTime defaultTimeLocale "%A, %B %d, %Y"
|
||||
|
||||
main = do
|
||||
t <- liftM2 utcToLocalTime getCurrentTimeZone getCurrentTime
|
||||
mapM_ putStrLn [format1 t, format2 t]
|
||||
29
Task/Date-format/Java/date-format.java
Normal file
29
Task/Date-format/Java/date-format.java
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.text.DateFormatSymbols;
|
||||
import java.util.Date;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
public class Dates
|
||||
{
|
||||
public static void main(final 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));
|
||||
|
||||
//using DateFormat
|
||||
Date date = new Date();
|
||||
DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
|
||||
System.out.println(format1.format(date));
|
||||
DateFormat format2 = new SimpleDateFormat("EEEE, MMMM dd, yyyy");
|
||||
System.out.println(format2.format(date));
|
||||
}
|
||||
}
|
||||
8
Task/Date-format/JavaScript/date-format.js
Normal file
8
Task/Date-format/JavaScript/date-format.js
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
var
|
||||
now = new Date(),
|
||||
fmt1 = now.getFullYear() + '-' + (1 + now.getMonth()) + '-' + now.getDate(),
|
||||
weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
|
||||
months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
||||
fmt2 = weekdays[now.getDay()] + ', ' + months[now.getMonth()] + ' ' + now.getDate() + ', ' + now.getFullYear();
|
||||
print(fmt1);
|
||||
print(fmt2);
|
||||
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" ) )
|
||||
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
|
||||
4
Task/Date-format/PHP/date-format.php
Normal file
4
Task/Date-format/PHP/date-format.php
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<?php
|
||||
echo date('Y-m-d', time())."\n";
|
||||
echo date('l, F j, Y', time())."\n";
|
||||
?>
|
||||
4
Task/Date-format/Perl/date-format-1.pl
Normal file
4
Task/Date-format/Perl/date-format-1.pl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
use 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";
|
||||
4
Task/Date-format/Perl/date-format-2.pl
Normal file
4
Task/Date-format/Perl/date-format-2.pl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
use POSIX;
|
||||
|
||||
print strftime('%Y-%m-%d', localtime), "\n";
|
||||
print strftime('%A, %B %d, %Y', localtime), "\n";
|
||||
10
Task/Date-format/PicoLisp/date-format.l
Normal file
10
Task/Date-format/PicoLisp/date-format.l
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
(let (Date (date) Lst (date Date))
|
||||
(prinl (dat$ Date "-")) # 2010-02-19
|
||||
(prinl # Friday, February 19, 2010
|
||||
(day Date)
|
||||
", "
|
||||
(get *MonFmt (cadr Lst))
|
||||
" "
|
||||
(caddr Lst)
|
||||
", "
|
||||
(car Lst) ) )
|
||||
6
Task/Date-format/Python/date-format.py
Normal file
6
Task/Date-format/Python/date-format.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import datetime
|
||||
today = datetime.date.today()
|
||||
# This one is built in:
|
||||
print today.isoformat()
|
||||
# Or use a format string for full flexibility:
|
||||
print today.strftime('%Y-%m-%d')
|
||||
3
Task/Date-format/R/date-format.r
Normal file
3
Task/Date-format/R/date-format.r
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
now <- Sys.time()
|
||||
strftime(now, "%Y-%m-%d")
|
||||
strftime(now, "%A, %B %d, %Y")
|
||||
11
Task/Date-format/REXX/date-format.rexx
Normal file
11
Task/Date-format/REXX/date-format.rexx
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/*show current date in yyyy-mm-dd and also Dayofweek, Month dd, yyyy*/
|
||||
x=date('s') /* yyyymmdd */
|
||||
yyyy=left(x,4) /* pick off the year. */
|
||||
dd=right(x,2) /* pick off the day of month */
|
||||
say yyyy'-'substr(x,5,2)"-"dd /*yyyy-mm-dd with leading 0s */
|
||||
|
||||
weekday =date('w') /* Dayofweek (Saturday) */
|
||||
month =date('m') /* Month (December) */
|
||||
zdd =dd+0 /* remove leading zero of DD */
|
||||
say weekday',' month zdd"," yyyy /*Month dd, yyyy */
|
||||
/*stick a fork in it, we're done.*/
|
||||
13
Task/Date-format/Racket/date-format.rkt
Normal file
13
Task/Date-format/Racket/date-format.rkt
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#lang racket
|
||||
(require srfi/19)
|
||||
|
||||
;;; The first required format is an ISO-8601 year-month-day format, predefined
|
||||
;;; as ~1 in date->string
|
||||
(displayln (date->string (current-date) "~1"))
|
||||
|
||||
;;; You should be able to see how each of the components of the following format string
|
||||
;;; work...
|
||||
;;; ~d is zero padded day of month:
|
||||
(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"))
|
||||
3
Task/Date-format/Ruby/date-format.rb
Normal file
3
Task/Date-format/Ruby/date-format.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
puts Time.now
|
||||
puts Time.now.strftime('%Y-%m-%d')
|
||||
puts Time.now.strftime('%A, %B %d, %Y')
|
||||
3
Task/Date-format/Scala/date-format.scala
Normal file
3
Task/Date-format/Scala/date-format.scala
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
val now=new Date()
|
||||
println("%tF".format(now))
|
||||
println("%1$tA, %1$tB %1$td, %1$tY".format(now))
|
||||
3
Task/Date-format/Tcl/date-format.tcl
Normal file
3
Task/Date-format/Tcl/date-format.tcl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
set now [clock seconds]
|
||||
puts [clock format $now -format "%Y-%m-%d"]
|
||||
puts [clock format $now -format "%A, %B %d, %Y"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue