.NET DateTime 显示格式
format 参数应包含单个格式说明符 (请参阅 标准日期和时间格式字符串) 或自定义格式模式 (请参阅 Cadenas con formato de fecha y hora personalizado),它定义了返回字符串的格式。如果 format 是 null 或使用空字符串,常规格式说明符,G。
此方法使用派生自当前区域性的格式设置信息。有关详细信息,请参阅CurrentCulture。
对调用方的说明:
ToString(String) 方法使用由当前区域性的日历中返回的字符串表示形式的日期和时间。如果当前值 DateTime 实例是早于Calendar.MinSupportedDateTime 或更高版本比 Calendar.MaxSupportedDateTime, ,该方法将引发 ArgumentOutOfRangeException。下面的示例进行了这方面的演示。它会尝试设置的范围之外的日期的格式 HebrewCalendar 类在当前区域性为希伯来语 (以色列) 时。
using System;
using System.Globalization;
using System.Threading; public class Example
{
public static void Main()
{
DateTime date1 = new DateTime(, , );
CultureInfo dft;
CultureInfo heIL = new CultureInfo("he-IL");
heIL.DateTimeFormat.Calendar = new HebrewCalendar(); // Change current culture to he-IL.
dft = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = heIL; // Display the date using the current culture's calendar.
try {
Console.WriteLine(date1.ToString("G"));
}
catch (ArgumentOutOfRangeException) {
Console.WriteLine("{0} is earlier than {1} or later than {2}",
date1.ToString("d", CultureInfo.InvariantCulture),
heIL.DateTimeFormat.Calendar.MinSupportedDateTime.ToString("d", CultureInfo.InvariantCulture),
heIL.DateTimeFormat.Calendar.MaxSupportedDateTime.ToString("d", CultureInfo.InvariantCulture));
} // Restore the default culture.
Thread.CurrentThread.CurrentCulture = dft;
}
}
// The example displays the following output:
// 07/21/1550 is earlier than 01/01/1583 or later than 09/29/2239
下面的示例使用的每个标准日期和时间格式字符串和选定的自定义日期和时间格式字符串来显示的字符串表示形式 DateTime 值。该示例的线程当前区域性为 EN-US。
using System; public class DateToStringExample
{
public static void Main()
{
DateTime dateValue = new DateTime(, , , , , );
// Create an array of standard format strings.
string[] standardFmts = {"d", "D", "f", "F", "g", "G", "m", "o",
"R", "s", "t", "T", "u", "U", "y"};
// Output date and time using each standard format string.
foreach (string standardFmt in standardFmts)
Console.WriteLine("{0}: {1}", standardFmt,
dateValue.ToString(standardFmt));
Console.WriteLine(); // Create an array of some custom format strings.
string[] customFmts = {"h:mm:ss.ff t", "d MMM yyyy", "HH:mm:ss.f",
"dd MMM HH:mm:ss", @"\Mon\t\h\: M", "HH:mm:ss.ffffzzz" };
// Output date and time using each custom format string.
foreach (string customFmt in customFmts)
Console.WriteLine("'{0}': {1}", customFmt,
dateValue.ToString(customFmt));
}
}
// This example displays the following output to the console:
// d: 6/15/2008
// D: Sunday, June 15, 2008
// f: Sunday, June 15, 2008 9:15 PM
// F: Sunday, June 15, 2008 9:15:07 PM
// g: 6/15/2008 9:15 PM
// G: 6/15/2008 9:15:07 PM
// m: June 15
// o: 2008-06-15T21:15:07.0000000
// R: Sun, 15 Jun 2008 21:15:07 GMT
// s: 2008-06-15T21:15:07
// t: 9:15 PM
// T: 9:15:07 PM
// u: 2008-06-15 21:15:07Z
// U: Monday, June 16, 2008 4:15:07 AM
// y: June, 2008
//
// 'h:mm:ss.ff t': 9:15:07.00 P
// 'd MMM yyyy': 15 Jun 2008
// 'HH:mm:ss.f': 21:15:07.0
// 'dd MMM HH:mm:ss': 15 Jun 21:15:07
// '\Mon\t\h\: M': Month: 6
// 'HH:mm:ss.ffffzzz': 21:15:07.0000-07:00
连接:https://msdn.microsoft.com/zh-cn/library/zdtaw1bw(v=vs.110).aspx
.NET DateTime 显示格式的更多相关文章
- 随心所欲的DateTime显示格式
任何项目,难免会碰到DateTime的显示问题,.net框架虽提供丰富多样的显示方法,但我很少使用,因老忘记细节,每次都要纠结到底月份在前还是年份在前:日期分隔符到底是“/”,还是“\”,还是“-”等 ...
- MySQL中DATETIME、DATE和TIMESTAMP类型的区别
一.TIMESTAMP 显示格式:YYYY-MM-DD HH:MM:SS 时间范围:[ '1970-01-01 00:00:00'到'2037-12-31 23:59:59'] TIMESTAMP D ...
- DataTime显示格式【转】
随心所欲的DateTime显示格式 任何项目,难免会碰到DateTime的显示问题,.net框架虽提供丰富多样的显示方法,但我很少使用,因老忘记细节,每次都要纠结到底月份在前还是年份在前:日期分隔符到 ...
- 我的MYSQL学习心得(四) 数据类型
我的MYSQL学习心得(四) 数据类型 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(五) 运 ...
- Mysql学习笔记(一)数据类型
原文:Mysql学习笔记(一)数据类型 学习内容: Mysql基本数据类型. 1.数字类型.. i.整型 Mysql数据类型 含义(有符号) tinyint(m ...
- mysql支持的数据类型及其测试
原文:mysql支持的数据类型及其测试 1.基础知识 1.1如何来查看mysql的帮助手册 ?int Help float; 1.2创建表的规则 CREATE TABLE [IF NOT EXISTS ...
- MySQL学习分享-->日期时间类型
日期时间类型 ①如果要用来表示年月日时分秒,一般使用datetime类型: ②如果要用来表示年月日,一般使用date类型: ③如果要表示时分秒,一般使用time类型: ④如果只是表示年份,一般使用ye ...
- mysql中data和datatime的区别
1.显示格式的区别 Date显示格式:YYYY-MM-DD:DateTime显示格式:YYYY-MM-DD HH:mm:ss. 2.显示范围的区别 Date显示范围是1601-01-01 到 9999 ...
- 记自己在mybatis中设置jdbcType的一个坑
项目是用ssm搭建的.主要是为app数据接口.其中有一个需求就app想要查询一段时间内某个用户的测量信息,所以app给我后端传递了3个参数,分别是appuserId(String),startDate ...
随机推荐
- Linux Tomcat 6.0安装配置实践总结
系统环境: Red Hat Enterprise Linux Server release 5.7 (Tikanga) 64位 Tomcat下载 从官方网站 http://tomcat.apache ...
- 使用管道符在PowerShell中进行各种数据操作
最近在培训PowerShell,在讲到Pipeline的时候,对于我这种长期和数据(数据库)打交道的人来说,觉得很实用,所以写此博文,记录一下. 无论是在Linux中写Bash脚本还是在Window上 ...
- Lucene索引文件学习
最近在做搜索,抽空看一下lucene,资料挺多的,不过大部分都是3.x了--在对着官方文档大概看一下. 优化后的lucene索引文件(4.9.0) 一.段文件 1.段文件:segments_5p和s ...
- shell脚本中生成延时
#!/bin/bash echo -n count: tput sc count=; while true; do ]; then let count++; ; tput rc tput ed ech ...
- Linux系统有7个运行级别(runlevel)
Linux系统有7个运行级别(runlevel) 运行级别0:系统停机状态,系统默认运行级别不能设为0,否则不能正常启动 运行级别1:单用户工作状态,root权限,用于系统维护,禁止远程登陆 运行级别 ...
- 使用ab进行压力测试详解
ab是apache自带的压力测试工具,非常好用.转载几篇对ab工具的详细使用的博文.猛击下面的链接地址 http://www.365mini.com/page/apache-benchmark.htm ...
- DOM document object model learn
DOM对W3C DOM而言,HTML文档中任何一样东西都是一个节点,而且节点之间是有层次的.如<p>I am a JavaScript hacker.</p>有两个节点,一个是 ...
- 【原】迎接微信winphone 5.0 版本的IE10样式兼容
微信 Android 5.1 和 iPhone 5.1 已正式发布了,据说本12月底,微信将推出 Winphone 5.0版本,全面支持微信支付,它绑定 IE10 浏览器,那么做微信公众号的 H5 页 ...
- Fullscreen API 全屏显示网页
可参考文档:http://blog.csdn.net/tywali/article/details/8623938 脚本代码 <script type="text/javascript ...
- 【别人的老师VS你的老师 】同样是老师,差别怎么这么大呢!?