- 浏览: 3013612 次
- 性别:
- 来自: 海外
文章分类
- 全部博客 (430)
- Programming Languages (23)
- Compiler (20)
- Virtual Machine (57)
- Garbage Collection (4)
- HotSpot VM (26)
- Mono (2)
- SSCLI Rotor (1)
- Harmony (0)
- DLR (19)
- Ruby (28)
- C# (38)
- F# (3)
- Haskell (0)
- Scheme (1)
- Regular Expression (5)
- Python (4)
- ECMAScript (2)
- JavaScript (18)
- ActionScript (7)
- Squirrel (2)
- C (6)
- C++ (10)
- D (2)
- .NET (13)
- Java (86)
- Scala (1)
- Groovy (3)
- Optimization (6)
- Data Structure and Algorithm (3)
- Books (4)
- WPF (1)
- Game Engines (7)
- 吉里吉里 (12)
- UML (1)
- Reverse Engineering (11)
- NSIS (4)
- Utilities (3)
- Design Patterns (1)
- Visual Studio (9)
- Windows 7 (3)
- x86 Assembler (1)
- Android (2)
- School Assignment / Test (6)
- Anti-virus (1)
- REST (1)
- Profiling (1)
- misc (39)
- NetOA (12)
- rant (6)
- anime (5)
- Links (12)
- CLR (7)
- GC (1)
- OpenJDK (2)
- JVM (4)
- KVM (0)
- Rhino (1)
- LINQ (2)
- JScript (0)
- Nashorn (0)
- Dalvik (1)
- DTrace (0)
- LLVM (0)
- MSIL (0)
最新评论
-
mldxs:
虽然很多还是看不懂,写的很好!
虚拟机随谈(一):解释器,树遍历解释器,基于栈与基于寄存器,大杂烩 -
HanyuKing:
Java的多维数组 -
funnyone:
Java 8的default method与method resolution -
ljs_nogard:
Xamarin workbook - .Net Core 中不 ...
LINQ的恶搞…… -
txm119161336:
allocatestlye1 顺序为 // Fields o ...
最近做的两次Java/JVM分享的概要
好几天没写东西了……新年什么的事情特别多 OTL
这几天一直在应付考试。总算都考完了。另外也读了好些以前没接触过的方面的资料,像是Programming Ruby之类。收获不少,不过没时间在这边记录。话说Programming Ruby和Ruby Cookbook的中文版分别是99和98元,现在的技术书真是太贵了 =_=|||
记点小东西。获取带格式的当前日期/时间的方法。C#的ToString()果然还是我觉得最有爱的format方式。不过脚本语言一般也都会提供非常方便的方法,像PHP、Perl和Ruby等等都有相当不错的方法;JavaScript虽然没提供format方法,但自己写一个不废什么事。
我们都知道C/C++里提供了__DATE__和__TIME__宏,不过这两个宏记录的是编译时的日期和时间,而且无法自定义格式,跟这里讨论的可以说是完全没关系……
============================================================
DOS Batch File(on Windows NT):
主要依靠命令行的date /T与time /T命令来分别获取当前系统日期和时间。
例子:
2008-01-05 星期六
11:20
http://www.robvanderwoude.com/datetiment.html
============================================================
Java:
Java里相关的几个类算是java.util.Date,java.util.Time,java.util.Calendar,java.text.DateFormat,java.text.SimpleDateFormat等。
这里的例子里我没有使用自定义格式,直接用了标准格式中的DateFormat.FULL所指定的格式。
如果使用SimpleDateFormat则可以指定自定义格式的参数:
============================================================
Scala:
Java平台上的一种函数式脚本语言。它可以依靠Java的标准库来完成操作,所以跟Java放在一起来记录。
============================================================
Velocity:
http://www.java2s.com/Code/Java/Velocity/HowtouseDateinVelocity.htm
============================================================
C#:
格式参数可以参考MSDN: .NET Framework Developer's Guide - Standard Date and Time Format Strings
引用MSDN上的简明表格如下:(http://msdn2.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.aspx
标准格式:
自定义格式:
C#另外有DateTime.UtcNow,用于获取当前的UTC时间。
虽然是用C#来说,其它在.NET Framework上运行的程序语言当然也能用同样的类库,例如说C++/CLI、VB.NET、JScript.NET等,不重复记录了。
============================================================
JavaScript:
JavaScript没有内建的对日期的format方法。通常的做法是自己写一个方法接到Date.prototype.format上,通过使用getYear()、getMonth()、getDay()等方法与正则表达式配合来实现根据format string指定输出的日期格式。
上面的方法是豆腐写的,多谢哦。能用这种简短的方法来写还是多得JavaScript采用UNICODE为内置字符编码。像Ruby就没办法直接用String#[]和fixnum#chr来处理非ASCII字符。
============================================================
D: (引用自 http://www.digitalmars.com/d/phobos/std_date.html)
D(Phobos)里的d_time基本上就是用UTC时间的。转换成别的形式时才带上时区等的计算。
不过D的标准库目前对英语以外的语言还是不够友善,可惜。
另外Phobos里这toString()的输出形式固定是"Www Mmm dd hh:mm:ss GMT+-TZ yyyy"。另外的toDateString()是"Www Mmm dd yyyy",而toTimeString()是"hh:mm:ss GMT+-TZ"。
============================================================
PHP:
格式参数:
我不熟悉PHP,无法肯定这东西有没有写错……
============================================================
Ruby:
Ruby这边基本上就是通过Date和Time来解决这问题。有Date::today和Time::now,另外就是Date::strftime和Time::strftime。不过Ruby在对中文的支持上也还是不够好啊(还是说我没弄清楚该怎么用?),要是能指定Locale就好了。
Time实例里有完整的时间信息,从年份到秒都有记录。而Date只记录到天,并且有更加严格的检查(以及对Gregorian历法的不同支持等)。
============================================================
Perl:
Perl的话,装上Date::Format会方便很多。以往的做法是通过localtime()获取毫秒的时间,然后通过Date::Format提供的time2str()函数来转换成自定义的格式。不过从Perl6开始提供了date()和utcdate()来获取当前时间。
这几天一直在应付考试。总算都考完了。另外也读了好些以前没接触过的方面的资料,像是Programming Ruby之类。收获不少,不过没时间在这边记录。话说Programming Ruby和Ruby Cookbook的中文版分别是99和98元,现在的技术书真是太贵了 =_=|||
记点小东西。获取带格式的当前日期/时间的方法。C#的ToString()果然还是我觉得最有爱的format方式。不过脚本语言一般也都会提供非常方便的方法,像PHP、Perl和Ruby等等都有相当不错的方法;JavaScript虽然没提供format方法,但自己写一个不废什么事。
我们都知道C/C++里提供了__DATE__和__TIME__宏,不过这两个宏记录的是编译时的日期和时间,而且无法自定义格式,跟这里讨论的可以说是完全没关系……
============================================================
DOS Batch File(on Windows NT):
主要依靠命令行的date /T与time /T命令来分别获取当前系统日期和时间。
例子:
2008-01-05 星期六
11:20
http://www.robvanderwoude.com/datetiment.html
============================================================
Java:
import java.util.Date; import java.util.Locale; import java.text.DateFormat; public class Greet { public static void main(String[] args) { DateFormat df = DateFormat.getDateTimeInstance( DateFormat.FULL, DateFormat.SHORT, Locale.CHINA); String message = df.format(new Date()); System.out.println(message); } } // 2008年1月4日 星期五 下午07:54
Java里相关的几个类算是java.util.Date,java.util.Time,java.util.Calendar,java.text.DateFormat,java.text.SimpleDateFormat等。
这里的例子里我没有使用自定义格式,直接用了标准格式中的DateFormat.FULL所指定的格式。
如果使用SimpleDateFormat则可以指定自定义格式的参数:
引用
Letter Date or Time Component Presentation Examples
G Era designator Text AD
y Year Year 1996; 96
M Month in year Month July; Jul; 07
w Week in year Number 27
W Week in month Number 2
D Day in year Number 189
d Day in month Number 10
F Day of week in month Number 2
E Day in week Text Tuesday; Tue
a Am/pm marker Text PM
H Hour in day (0-23) Number 0
k Hour in day (1-24) Number 24
K Hour in am/pm (0-11) Number 0
h Hour in am/pm (1-12) Number 12
m Minute in hour Number 30
s Second in minute Number 55
S Millisecond Number 978
z Time zone General time zone Pacific Standard Time; PST; GMT-08:00
Z Time zone RFC 822 time zone -0800
G Era designator Text AD
y Year Year 1996; 96
M Month in year Month July; Jul; 07
w Week in year Number 27
W Week in month Number 2
D Day in year Number 189
d Day in month Number 10
F Day of week in month Number 2
E Day in week Text Tuesday; Tue
a Am/pm marker Text PM
H Hour in day (0-23) Number 0
k Hour in day (1-24) Number 24
K Hour in am/pm (0-11) Number 0
h Hour in am/pm (1-12) Number 12
m Minute in hour Number 30
s Second in minute Number 55
S Millisecond Number 978
z Time zone General time zone Pacific Standard Time; PST; GMT-08:00
Z Time zone RFC 822 time zone -0800
============================================================
Scala:
import java.util.{Date, Locale} import java.text.DateFormat import java.text.DateFormat._ object ChinaDate { def main(args: Array[String]) { val now = new Date val df = getDateInstance(LONG, Locale.CHINA) println(df format now) } }
Java平台上的一种函数式脚本语言。它可以依靠Java的标准库来完成操作,所以跟Java放在一起来记录。
============================================================
Velocity:
http://www.java2s.com/Code/Java/Velocity/HowtouseDateinVelocity.htm
============================================================
C#:
using System; sealed class Greet { static void Main(string[] args) { string nowString = DateTime.Now.ToString("yyyy年MM月dd日 dddd tt hh时mm分"); Console.WriteLine(nowString); } } // 2008年01月04日 星期五 下午 08时11分
格式参数可以参考MSDN: .NET Framework Developer's Guide - Standard Date and Time Format Strings
引用MSDN上的简明表格如下:(http://msdn2.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.aspx
标准格式:
引用
Format pattern
Associated Property/Description
d
ShortDatePattern
D
LongDatePattern
f
Full date and time (long date and short time)
F
FullDateTimePattern (long date and long time)
g
General (short date and short time)
G
General (short date and long time)
m, M
MonthDayPattern
o, O
Round-trip date/time pattern; with this format pattern, the formatting or parsing operation always uses the invariant culture
r, R
RFC1123Pattern; with this format pattern, the formatting or parsing operation always uses the invariant culture
s
SortableDateTimePattern (based on ISO 8601) using local time; with this format pattern, the formatting or parsing operation always uses the invariant culture
t
ShortTimePattern
T
LongTimePattern
u
UniversalSortableDateTimePattern using the format for universal time display; with this format pattern, the formatting or parsing operation always uses the invariant culture
U
Full date and time (long date and long time) using universal time
y, Y
YearMonthPattern
Associated Property/Description
d
ShortDatePattern
D
LongDatePattern
f
Full date and time (long date and short time)
F
FullDateTimePattern (long date and long time)
g
General (short date and short time)
G
General (short date and long time)
m, M
MonthDayPattern
o, O
Round-trip date/time pattern; with this format pattern, the formatting or parsing operation always uses the invariant culture
r, R
RFC1123Pattern; with this format pattern, the formatting or parsing operation always uses the invariant culture
s
SortableDateTimePattern (based on ISO 8601) using local time; with this format pattern, the formatting or parsing operation always uses the invariant culture
t
ShortTimePattern
T
LongTimePattern
u
UniversalSortableDateTimePattern using the format for universal time display; with this format pattern, the formatting or parsing operation always uses the invariant culture
U
Full date and time (long date and long time) using universal time
y, Y
YearMonthPattern
自定义格式:
引用
Format pattern
Description
d, %d
The day of the month. Single-digit days do not have a leading zero. The application specifies "%d" if the format pattern is not combined with other format patterns.
dd
The day of the month. Single-digit days have a leading zero.
ddd
The abbreviated name of the day of the week, as defined in AbbreviatedDayNames.
dddd
The full name of the day of the week, as defined in DayNames.
f, %f
The fraction of a second in single-digit precision. The remaining digits are truncated. The application specifies "%f" if the format pattern is not combined with other format patterns.
ff
The fraction of a second in double-digit precision. The remaining digits are truncated.
fff
The fraction of a second in three-digit precision. The remaining digits are truncated.
ffff
The fraction of a second in four-digit precision. The remaining digits are truncated.
fffff
The fraction of a second in five-digit precision. The remaining digits are truncated.
ffffff
The fraction of a second in six-digit precision. The remaining digits are truncated.
fffffff
The fraction of a second in seven-digit precision. The remaining digits are truncated.
F, %F
Displays the most significant digit of the seconds fraction. Nothing is displayed if the digit is zero. The application specifies "%F" if the format pattern is not combined with other format patterns.
FF
Displays the two most significant digits of the seconds fraction. However, trailing zeros, or two zero digits, are not displayed.
FFF
Displays the three most significant digits of the seconds fraction. However, trailing zeros, or three zero digits, are not displayed.
FFFF
Displays the four most significant digits of the seconds fraction. However, trailing zeros, or four zero digits, are not displayed.
FFFFF
Displays the five most significant digits of the seconds fraction. However, trailing zeros, or five zero digits, are not displayed.
FFFFFF
Displays the six most significant digits of the seconds fraction. However, trailing zeros, or six zero digits, are not displayed.
FFFFFFF
Displays the seven most significant digits of the seconds fraction. However, trailing zeros, or seven zero digits, are not displayed.
gg
The period or era. This pattern is ignored if the date to be formatted does not have an associated period or era string.
h, %h
The hour in a 12-hour clock. Single-digit hours do not have a leading zero. The application specifies "%h" if the format pattern is not combined with other format patterns.
hh
The hour in a 12-hour clock. Single-digit hours have a leading zero.
H, %H
The hour in a 24-hour clock. Single-digit hours do not have a leading zero. The application specifies "%H" if the format pattern is not combined with other format patterns.
HH
The hour in a 24-hour clock. Single-digit hours have a leading zero.
K
Different values of the Kind property, that is, Local, Utc, or Unspecified.
m, %m
The minute. Single-digit minutes do not have a leading zero. The application specifies "%m" if the format pattern is not combined with other format patterns.
mm
The minute. Single-digit minutes have a leading zero.
M, %M
The numeric month. Single-digit months do not have a leading zero. The application specifies "%M" if the format pattern is not combined with other format patterns.
MM
The numeric month. Single-digit months have a leading zero.
MMM
The abbreviated name of the month, as defined in AbbreviatedMonthNames.
MMMM
The full name of the month, as defined in MonthNames.
s, %s
The second. Single-digit seconds do not have a leading zero. The application specifies "%s" if the format pattern is not combined with other format patterns.
ss
The second. Single-digit seconds have a leading zero.
t, %t
The first character in the AM/PM designator defined in AMDesignator or PMDesignator, if any. The application specifies "%t" if the format pattern is not combined with other format patterns.
tt
The AM/PM designator defined in AMDesignator or PMDesignator, if any. Your application should use this format pattern for languages for which it is necessary to maintain the distinction between AM and PM. An example is Japanese, for which the AM and PM designators differ in the second character instead of the first character.
y, %y
The year without the century. If the year without the century is less than 10, the year is displayed with no leading zero. The application specifies "%y" if the format pattern is not combined with other format patterns.
yy
The year without the century. If the year without the century is less than 10, the year is displayed with a leading zero.
yyy
The year in three digits. If the year is less than 100, the year is displayed with a leading zero.
yyyy
The year in four or five digits (depending on the calendar used), including the century. Pads with leading zeros to get four digits. Thai Buddhist and Korean calendars have five-digit years. Users selecting the "yyyy" pattern see all five digits without leading zeros for calendars that have five digits. Exception: the Japanese and Taiwan calendars always behave as if "yy" is selected.
yyyyy
The year in five digits. Pads with leading zeros to get five digits. Exception: the Japanese and Taiwan calendars always behave as if "yy" is selected.
yyyyyy
The year in six digits. Pads with leading zeros to get six digits. Exception: the Japanese and Taiwan calendars always behave as if "yy" is selected. The pattern can be continued with a longer string of "y"s padding with more leading zeros.
z, %z
The time zone offset ("+" or "-" followed by the hour only). Single-digit hours do not have a leading zero. For example, Pacific Standard Time is "-8". The application specifies "%z" if the format pattern is not combined with other format patterns.
zz
The time zone offset ("+" or "-" followed by the hour only). Single-digit hours have a leading zero. For example, Pacific Standard Time is "-08".
zzz
The full time zone offset ("+" or "-" followed by the hour and minutes). Single-digit hours and minutes have leading zeros. For example, Pacific Standard Time is "-08:00".
:
The default time separator defined in TimeSeparator.
/
The default date separator defined in DateSeparator.
% c
Where c is a format pattern if used alone. To use format pattern "d", "f", "F", "h", "m", "s", "t", "y", "z", "H", or "M" by itself, the application specifies "%d", "%f", "%F", "%h", "%m", "%s", "%t", "%y", "%z", "%H", or "%M".
The "%" character can be omitted if the format pattern is combined with literal characters or other format patterns.
\ c
Where c is any character. Displays the character literally. To display the backslash character, the application should use "\\".
Description
d, %d
The day of the month. Single-digit days do not have a leading zero. The application specifies "%d" if the format pattern is not combined with other format patterns.
dd
The day of the month. Single-digit days have a leading zero.
ddd
The abbreviated name of the day of the week, as defined in AbbreviatedDayNames.
dddd
The full name of the day of the week, as defined in DayNames.
f, %f
The fraction of a second in single-digit precision. The remaining digits are truncated. The application specifies "%f" if the format pattern is not combined with other format patterns.
ff
The fraction of a second in double-digit precision. The remaining digits are truncated.
fff
The fraction of a second in three-digit precision. The remaining digits are truncated.
ffff
The fraction of a second in four-digit precision. The remaining digits are truncated.
fffff
The fraction of a second in five-digit precision. The remaining digits are truncated.
ffffff
The fraction of a second in six-digit precision. The remaining digits are truncated.
fffffff
The fraction of a second in seven-digit precision. The remaining digits are truncated.
F, %F
Displays the most significant digit of the seconds fraction. Nothing is displayed if the digit is zero. The application specifies "%F" if the format pattern is not combined with other format patterns.
FF
Displays the two most significant digits of the seconds fraction. However, trailing zeros, or two zero digits, are not displayed.
FFF
Displays the three most significant digits of the seconds fraction. However, trailing zeros, or three zero digits, are not displayed.
FFFF
Displays the four most significant digits of the seconds fraction. However, trailing zeros, or four zero digits, are not displayed.
FFFFF
Displays the five most significant digits of the seconds fraction. However, trailing zeros, or five zero digits, are not displayed.
FFFFFF
Displays the six most significant digits of the seconds fraction. However, trailing zeros, or six zero digits, are not displayed.
FFFFFFF
Displays the seven most significant digits of the seconds fraction. However, trailing zeros, or seven zero digits, are not displayed.
gg
The period or era. This pattern is ignored if the date to be formatted does not have an associated period or era string.
h, %h
The hour in a 12-hour clock. Single-digit hours do not have a leading zero. The application specifies "%h" if the format pattern is not combined with other format patterns.
hh
The hour in a 12-hour clock. Single-digit hours have a leading zero.
H, %H
The hour in a 24-hour clock. Single-digit hours do not have a leading zero. The application specifies "%H" if the format pattern is not combined with other format patterns.
HH
The hour in a 24-hour clock. Single-digit hours have a leading zero.
K
Different values of the Kind property, that is, Local, Utc, or Unspecified.
m, %m
The minute. Single-digit minutes do not have a leading zero. The application specifies "%m" if the format pattern is not combined with other format patterns.
mm
The minute. Single-digit minutes have a leading zero.
M, %M
The numeric month. Single-digit months do not have a leading zero. The application specifies "%M" if the format pattern is not combined with other format patterns.
MM
The numeric month. Single-digit months have a leading zero.
MMM
The abbreviated name of the month, as defined in AbbreviatedMonthNames.
MMMM
The full name of the month, as defined in MonthNames.
s, %s
The second. Single-digit seconds do not have a leading zero. The application specifies "%s" if the format pattern is not combined with other format patterns.
ss
The second. Single-digit seconds have a leading zero.
t, %t
The first character in the AM/PM designator defined in AMDesignator or PMDesignator, if any. The application specifies "%t" if the format pattern is not combined with other format patterns.
tt
The AM/PM designator defined in AMDesignator or PMDesignator, if any. Your application should use this format pattern for languages for which it is necessary to maintain the distinction between AM and PM. An example is Japanese, for which the AM and PM designators differ in the second character instead of the first character.
y, %y
The year without the century. If the year without the century is less than 10, the year is displayed with no leading zero. The application specifies "%y" if the format pattern is not combined with other format patterns.
yy
The year without the century. If the year without the century is less than 10, the year is displayed with a leading zero.
yyy
The year in three digits. If the year is less than 100, the year is displayed with a leading zero.
yyyy
The year in four or five digits (depending on the calendar used), including the century. Pads with leading zeros to get four digits. Thai Buddhist and Korean calendars have five-digit years. Users selecting the "yyyy" pattern see all five digits without leading zeros for calendars that have five digits. Exception: the Japanese and Taiwan calendars always behave as if "yy" is selected.
yyyyy
The year in five digits. Pads with leading zeros to get five digits. Exception: the Japanese and Taiwan calendars always behave as if "yy" is selected.
yyyyyy
The year in six digits. Pads with leading zeros to get six digits. Exception: the Japanese and Taiwan calendars always behave as if "yy" is selected. The pattern can be continued with a longer string of "y"s padding with more leading zeros.
z, %z
The time zone offset ("+" or "-" followed by the hour only). Single-digit hours do not have a leading zero. For example, Pacific Standard Time is "-8". The application specifies "%z" if the format pattern is not combined with other format patterns.
zz
The time zone offset ("+" or "-" followed by the hour only). Single-digit hours have a leading zero. For example, Pacific Standard Time is "-08".
zzz
The full time zone offset ("+" or "-" followed by the hour and minutes). Single-digit hours and minutes have leading zeros. For example, Pacific Standard Time is "-08:00".
:
The default time separator defined in TimeSeparator.
/
The default date separator defined in DateSeparator.
% c
Where c is a format pattern if used alone. To use format pattern "d", "f", "F", "h", "m", "s", "t", "y", "z", "H", or "M" by itself, the application specifies "%d", "%f", "%F", "%h", "%m", "%s", "%t", "%y", "%z", "%H", or "%M".
The "%" character can be omitted if the format pattern is combined with literal characters or other format patterns.
\ c
Where c is any character. Displays the character literally. To display the backslash character, the application should use "\\".
C#另外有DateTime.UtcNow,用于获取当前的UTC时间。
虽然是用C#来说,其它在.NET Framework上运行的程序语言当然也能用同样的类库,例如说C++/CLI、VB.NET、JScript.NET等,不重复记录了。
============================================================
JavaScript:
var now = new Date(); var nowString = date.toLocaleString()+' 星期'+'日一二三四五六'.charAt(date.getDay()); print(nowString); // 2008年1月4日 20:19:48 星期五
JavaScript没有内建的对日期的format方法。通常的做法是自己写一个方法接到Date.prototype.format上,通过使用getYear()、getMonth()、getDay()等方法与正则表达式配合来实现根据format string指定输出的日期格式。
上面的方法是豆腐写的,多谢哦。能用这种简短的方法来写还是多得JavaScript采用UNICODE为内置字符编码。像Ruby就没办法直接用String#[]和fixnum#chr来处理非ASCII字符。
============================================================
D: (引用自 http://www.digitalmars.com/d/phobos/std_date.html)
import std.date; void main(char[][] args) { // Grab the date and time relative to UTC d_time lNow = std.date.getUTCtime(); // Convert this into the local date and time for display. char[] lNowString = std.date.toString(lNow); printf("%.*s", lNowString); } // Fri Jan 04 23:16:58 GMT+0800 2008
D(Phobos)里的d_time基本上就是用UTC时间的。转换成别的形式时才带上时区等的计算。
不过D的标准库目前对英语以外的语言还是不够友善,可惜。
另外Phobos里这toString()的输出形式固定是"Www Mmm dd hh:mm:ss GMT+-TZ yyyy"。另外的toDateString()是"Www Mmm dd yyyy",而toTimeString()是"hh:mm:ss GMT+-TZ"。
============================================================
PHP:
<?php echo $showtime=date("Y年n月j日 H时i分A");?> <!-- 2008年1月4日 11时56分PM -->
格式参数:
引用
相关时间参数:
a - "am" 或是 "pm"
A - "AM" 或是 "PM"
d - 几日,二位数字,若不足二位则前面补零; 如: "01" 至 "31"
D - 星期几,三个英文字母; 如: "Fri"
F - 月份,英文全名; 如: "January"
h - 12 小时制的小时; 如: "01" 至 "12"
H - 24 小时制的小时; 如: "00" 至 "23"
g - 12 小时制的小时,不足二位不补零; 如: "1" 至 12"
G - 24 小时制的小时,不足二位不补零; 如: "0" 至 "23"
i - 分钟; 如: "00" 至 "59"
j - 几日,二位数字,若不足二位不补零; 如: "1" 至 "31"
l - 星期几,英文全名; 如: "Friday"
m - 月份,二位数字,若不足二位则在前面补零; 如: "01" 至 "12"
n - 月份,二位数字,若不足二位则不补零; 如: "1" 至 "12"
M - 月份,三个英文字母; 如: "Jan"
s - 秒; 如: "00" 至 "59"
S - 字尾加英文序数,二个英文字母; 如: "th","nd"
t - 指定月份的天数; 如: "28" 至 "31"
U - 总秒数
w - 数字型的星期几,如: "0" (星期日) 至 "6" (星期六)
Y - 年,四位数字; 如: "1999"
y - 年,二位数字; 如: "99"
z - 一年中的第几天; 如: "0" 至 "365"
a - "am" 或是 "pm"
A - "AM" 或是 "PM"
d - 几日,二位数字,若不足二位则前面补零; 如: "01" 至 "31"
D - 星期几,三个英文字母; 如: "Fri"
F - 月份,英文全名; 如: "January"
h - 12 小时制的小时; 如: "01" 至 "12"
H - 24 小时制的小时; 如: "00" 至 "23"
g - 12 小时制的小时,不足二位不补零; 如: "1" 至 12"
G - 24 小时制的小时,不足二位不补零; 如: "0" 至 "23"
i - 分钟; 如: "00" 至 "59"
j - 几日,二位数字,若不足二位不补零; 如: "1" 至 "31"
l - 星期几,英文全名; 如: "Friday"
m - 月份,二位数字,若不足二位则在前面补零; 如: "01" 至 "12"
n - 月份,二位数字,若不足二位则不补零; 如: "1" 至 "12"
M - 月份,三个英文字母; 如: "Jan"
s - 秒; 如: "00" 至 "59"
S - 字尾加英文序数,二个英文字母; 如: "th","nd"
t - 指定月份的天数; 如: "28" 至 "31"
U - 总秒数
w - 数字型的星期几,如: "0" (星期日) 至 "6" (星期六)
Y - 年,四位数字; 如: "1999"
y - 年,二位数字; 如: "99"
z - 一年中的第几天; 如: "0" 至 "365"
我不熟悉PHP,无法肯定这东西有没有写错……
============================================================
Ruby:
dayOfWeek = [ "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" ] t = Time.now nowString = t.strftime("%Y年%m月%d日 ") << dayOfWeek[t.strftime("%w").to_i] << t.strftime(" %H:%M %p") puts nowString # 2008年01月05日 星期六 00:25 AM
引用
%a - The abbreviated weekday name (``Sun'')
%A - The full weekday name (``Sunday'')
%b - The abbreviated month name (``Jan'')
%B - The full month name (``January'')
%c - The preferred local date and time representation
%d - Day of the month (01..31)
%H - Hour of the day, 24-hour clock (00..23)
%I - Hour of the day, 12-hour clock (01..12)
%j - Day of the year (001..366)
%m - Month of the year (01..12)
%M - Minute of the hour (00..59)
%p - Meridian indicator (``AM'' or ``PM'')
%S - Second of the minute (00..60)
%U - Week number of the current year, starting with the first Sunday as the first day of the first week (00..53)
%W - Week number of the current year, starting with the first Monday as the first day of the first week (00..53)
%w - Day of the week (Sunday is 0, 0..6)
%x - Preferred representation for the date alone, no time
%X - Preferred representation for the time alone, no date
%y - Year without a century (00..99)
%Y - Year with century
%Z - Time zone name
%% - Literal ``%'' character
%A - The full weekday name (``Sunday'')
%b - The abbreviated month name (``Jan'')
%B - The full month name (``January'')
%c - The preferred local date and time representation
%d - Day of the month (01..31)
%H - Hour of the day, 24-hour clock (00..23)
%I - Hour of the day, 12-hour clock (01..12)
%j - Day of the year (001..366)
%m - Month of the year (01..12)
%M - Minute of the hour (00..59)
%p - Meridian indicator (``AM'' or ``PM'')
%S - Second of the minute (00..60)
%U - Week number of the current year, starting with the first Sunday as the first day of the first week (00..53)
%W - Week number of the current year, starting with the first Monday as the first day of the first week (00..53)
%w - Day of the week (Sunday is 0, 0..6)
%x - Preferred representation for the date alone, no time
%X - Preferred representation for the time alone, no date
%y - Year without a century (00..99)
%Y - Year with century
%Z - Time zone name
%% - Literal ``%'' character
Ruby这边基本上就是通过Date和Time来解决这问题。有Date::today和Time::now,另外就是Date::strftime和Time::strftime。不过Ruby在对中文的支持上也还是不够好啊(还是说我没弄清楚该怎么用?),要是能指定Locale就好了。
Time实例里有完整的时间信息,从年份到秒都有记录。而Date只记录到天,并且有更加严格的检查(以及对Gregorian历法的不同支持等)。
============================================================
Perl:
Perl的话,装上Date::Format会方便很多。以往的做法是通过localtime()获取毫秒的时间,然后通过Date::Format提供的time2str()函数来转换成自定义的格式。不过从Perl6开始提供了date()和utcdate()来获取当前时间。
评论
3 楼
lwwin
2008-01-05
当时希望能够用BAT做一个和获得时间相关的东东+……+
结果是很囧的
PS:有这种EXE就好了,不过偶机器没.NETFRAMEWORK……
结果是很囧的
PS:有这种EXE就好了,不过偶机器没.NETFRAMEWORK……
2 楼
RednaxelaFX
2008-01-04
__DATE__ __TIME__ %date% 这些都无法定制,在这里可以说是毫无用处。不在这讨论范围内。
所以还是喜欢.NET Framework版的那个……
所以还是喜欢.NET Framework版的那个……
1 楼
lwwin
2008-01-04
%date%
发表评论
-
Sun JDK1.4.2_28有TieredCompilation
2014-05-12 08:48 0原来以前Sun的JDK 1.4.2 update 28就已经有 ... -
IBM JVM notes (2014 ver)
2014-05-11 07:16 0Sovereign JIT http://publib.bou ... -
Java 8的lambda表达式在OpenJDK8中的实现
2014-02-04 12:08 0三月份JDK8就要发布首发了,现在JDK8 release c ... -
基于LLVM实现VM的JIT的一些痛点
2014-01-07 17:25 0同事Philip Reames Sanjoy Das http ... -
tailcall notes
2013-12-27 07:42 0http://blogs.msdn.com/b/clrcode ... -
《自制编程语言》的一些笔记
2013-11-24 00:20 0http://kmaebashi.com/programmer ... -
字符串的一般封装方式的内存布局 (1): 元数据与字符串内容,整体还是分离?
2013-11-07 17:44 22244(Disclaimer:未经许可请 ... -
字符串的一般封装方式的内存布局 (0): 拿在手上的是什么
2013-11-04 18:22 21361(Disclaimer:未经许可请 ... -
字符串的一般封装方式的内存布局
2013-11-01 12:55 0(Disclaimer:未经许可请 ... -
关于string,内存布局,C++ std::string,CoW
2013-10-30 20:45 0(Disclaimer:未经许可请 ... -
Function.prototype.bind
2013-09-24 18:07 0polyfill http://stackoverflow. ... -
Java的instanceof是如何实现的
2013-09-22 16:57 0Java语言规范,Java SE 7版 http://docs ... -
struct做参数不能从寄存器传?
2013-08-28 23:33 0test test test struct Foo { i ... -
也谈类型: 数据, 类型, 标签
2013-08-18 01:59 0numeric tower http://en.wikiped ... -
SDCC 2012上做的JVM分享
2012-10-17 16:35 32538刚把在SDCC 2012做的JVM分享的演示稿上传了。 演示 ... -
运行时支持系统的“重量”
2012-10-12 16:08 0运行时支持系统的“重量” 好久没写博客了,可写的话题已经堆积 ... -
class?metaclass?meta-what?
2011-04-05 19:43 0http://en.wikipedia.org/wiki/Me ... -
“代码模式”与抽象
2010-10-28 15:21 0嗯,我是说“代码模式”,不是“设计模式”;这里指的是在给定的场 ... -
lvalue与rvalue
2010-09-03 00:40 0http://en.wikipedia.org/wiki/Va ... -
动态链接的“依据”
2010-02-09 09:54 0动态链接,意味着在生成的“东西”里留有符号信息,等到运行时再r ...
相关推荐
mysql 获取当前日期及格式化,mysql 获取当前日期及格式化简单方便mysql 获取当前日期及格式化
JavaScript获得当前日期是星期几,主要通过getDay函数获得当前日期是一个星期的第几天 <!DOCTYPE html> <html> <body> Click the button to display todays day of the week. <button onclick=...
Js获取当前日期时间及其它操作 还有一些自己风装好的方法,很好用,也很全。js的日期判断。
主要为大家详细介绍了Js获取当前日期时间及格式化代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
labview获取当前日期时间精确到毫秒字符串
整理出来的获取Android系统当前时间日期,看log
本内容介绍了“vue中怎么获取当前日期”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!具体步骤如下:1....
--获取当前日期(如:yyyymmdd) select CONVERT (nvarchar(12),GETDATE(),112)
用来获取当前日期的代码,格式 2015-03-13 00:00:00
本文实例讲述了js获取当前日期前七天的方法。分享给大家供大家参考。具体如下: //设置日期,当前日期的前七天 var myDate = new Date(); //获取今天日期 myDate.setDate(myDate.getDate() - 7); var dateArray = ...
C#获取当前各种格式日期, 以及sql数据库的当前日期获取
主要介绍了jquery获取当前日期的方法,涉及针对日期时间的操作技巧,具有一定参考借鉴价值,需要的朋友可以参考下
python获取当前日期
Mysql根据时间查询日期的优化技巧mysql 获取昨天日期、今天日期、明天日期以及前一个小时和后一个小时的时间解析MySQL中存储时间日期类型的选择问题JDBC中使用Java8的日期LocalDate和LocalDateTime操作mysql、...
VB 6.0获取当前系统日期,星期代码!
该程序是我写的博客“一起talk C栗子吧(第三十七回:C语言实例--获取当前日期和时间)”的配套程序,共享给大家使用
net中各种获取日期的方法,很详细,个人认为
Js获取当前日期时间及其它操作 .doc