快速业务通道

Java中一些获取当前日期的方法 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-14
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

Java中一些获取当前日期的方法(4)

时间:2011-10-07 javaeye RednaxelaFX

自定义格式:

引用

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 se

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号