It is format pattern of the date function of PHP and the date format library of JavaScript which has compatibility. However, because it is not the case that all patterns are mounted, please note. Japanese day of the week it is possible as the extended function which is not in PHP, to indicate the month name of the old calendar.
Please download from link below.
DateFormatter.js is loaded.
<script type="text/javascript" src="./DateFormatter.js"></script>
The format is done with format method of DateFormatter object. For example, when indicating present date time, it makes like below.
var now = new Date();
alert(DateFormatter.format(now, "Y/m/d H:i:s"));
As for indicatory result “2007/01/15 16:30:12”.
When the escape it does format letter, the # is attached immediately before. For example, when “Ymd is date” we would like to indicate, it becomes like below.
var now = new Date();
alert(DateFormatter.format(now, "#Y#m#d #i#s Ymd"));
In order each time without coding the call of DateFormatter not to have, there is also a method of expanding Date object.
Date.prototype.format = function(pattern) {
return DateFormatter.format(this, pattern);
}
var now = new Date();
alert(now.format("Y/m/d H:i:s"));
The male is completed is not, but by the fact that it makes global function, from also method of writing which PHP seems is possible.
function date(pattern, time) {
var d = new Date();
if (time != null) {
d.setTime(time);
}
return DateFormatter.format(d, pattern);
}
alert(date("Y/m/d H:i:s"));
Pattern | Explanation |
---|---|
Y | A full numeric representation of a year, 4 digits |
y | A two digit representation of a year |
m | Numeric representation of a month, with leading zeros |
n | Numeric representation of a month, without leading zeros |
F | A full textual representation of a month, such as January or March |
M | A short textual representation of a month, three letters |
O | Japanese old month name |
d | Day of the month, 2 digits with leading zeros |
j | Day of the month without leading zeros |
w | Numeric representation of the day of the week |
l | A full textual representation of the day of the week |
D | A textual representation of a day, three letters |
N | ISO-8601 numeric representation of the day of the week |
J | A Japanese textual representation of the day of the week |
g | 12-hour format of an hour without leading zeros |
G | 24-hour format of an hour without leading zeros |
h | 12-hour format of an hour with leading zeros |
H | 24-hour format of an hour with leading zeros |
i | Minutes with leading zeros |
s | Seconds, with leading zeros |
a | Lowercase Ante meridiem and Post meridiem (am or pm) |
A | Uppercase Ante meridiem and Post meridiem (AM or PM) |
S | English ordinal suffix for the day of the month, 2 characters |
z | The day of the year (starting from 0) |
t | Number of days in the given month |
L | Whether it's a leap year |
It is form for the test. Please try inputting format pattern.
It makes the BSD license. Use of the software (execution) it is free without restriction, but the case of redistribution, with the source code that, it is necessary to include the list disclaimer of copyright notice condition with that binary.