`
阿尔萨斯
  • 浏览: 4150955 次
社区版块
存档分类
最新评论

C# - 利用DateTime.ToString(string format)输出不同格式的日期

 
阅读更多
DateTime.ToString(string format)功能很强大,能输出不同格式的日期。以下把一些情况罗列出来,供大家参考。
  1. y代表年份。注意是小写的y,大写的Y并不代表年份。
  2. M表示月份。注意是大写的M,小写的m表示分钟。
  3. d表示日期。注意是小写的d,大写的D并不代表日期。
  4. h或H表示小时,注意h用的是12小时制,H用的是24小时制。
  5. m表示分钟。注意是小写的m,大写的M表示月份。
  6. s表示秒。注意大写的S并不代表秒。

以上所有罗列出来的格式会随着操作系统的不同和格式字符的个数不同而输出相应不同的格式。

分享到:
评论

相关推荐

    C# 日期函数 string.Format

    C# 日期函数 string.Format DateTime dt = DateTime.Now; Label1.Text = dt.ToString();//2005-11-5 13:21:25 Label2.Text = dt.ToFileTime().ToString();//127756416859912816 Label3.Text = dt.ToFileTimeUtc()...

    C#(ASP.NET)DateTime日期类型格式化显示

    String.Format( "yyyy-MM-dd ",yourDateTime); 4.用Convert方法转换日期显示格式: Convert.ToDateTime("2005-8-23").ToString ("yyMMdd",System.Globalization.DateTimeFormatInfo.InvariantInfo); //支持繁体...

    C#中时间的几种格式转换方法

    有时候我们要对C#时间进行转换,达到不同的显示效果 默认格式为:2005-6-614:33:34 如果要换成成200506,06-2005,2005-6-6或更多的该怎么办呢 我们要用到:DateTime.ToString的方法(String,IFormatProvider) 代码如下:...

    数字时钟,动态显示当前时间,C#源代码public string ProcessTime()

    数字时钟,动态显示当前时间,C#源代码public string ProcessTime() { string sTime; // Get the current time int iHour = DateTime.Now.Hour; int iMin = DateTime.Now.Minute; int iSec = DateTime.Now....

    数字时钟,动态显示当前时间,C#源代码

    数字时钟,动态显示当前时间,C#源代码 public string ProcessTime() { string sTime; // Get the current time int iHour = DateTime.Now.Hour; int iMin = DateTime.Now.Minute; int iSec = DateTime.Now....

    浅谈c#.net中巧用ToString()将日期转成想要的格式

    C#时间/日期格式大全,C#时间/日期函数大全 有时候我们要对时间进行转换,达到不同的显示效果 默认格式为:2005-6-6 14:33:34 如果要换成成200506,06-2005,2005-6-6或更多的该怎么办呢? 我们要用到: 代码如下:...

    c#漂亮的小时钟程序

    比较实用的c#小程序,小时钟 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; //...

    C#农历处理类 测试正常

    之前曾经上传过一个农历处理类,但遇到... return string.Format(@"{0} {1} 农历 {2} 当前时间:{3}", DateTime.Now.ToString("yyyy年MM月dd日"), dt.LongCNWeek, dt.CNDate, DateTime.Now.ToString("HH:mm:ss")); }

    C# String Format Tester 1.2

    C# String Format Tester是一个用来测试字符串格式化输出的小工具。工具很简单,可以用来测试DateTime、Int16、Int32、Int64、Decimal、Single、Double、Byte、Guid 这几个类型的ToString格式化输出。此工具还集成了...

    C#.net格式化时间字符串达到不同的显示效果

    有时候我们要对时间进行转换,达到不同的显示效果 默认格式为:2005-6-6 14:33:34 如果要换成成200506,06-2005,2005-6-6或更多的该怎么办呢 我们要用到:DateTime.ToString的方法(String, IFormatProvider) using ...

    C# 最全的日期正则表达式,没有之一

    richTextBox2.Text += string.Format("{0:0000}", i) + "\n"; } } 根据闰年的规则,很容易整理出规则,四年一闰; ([0-9]{2}(0[48]|[2468][048]|[13579][26]) 百年不闰,四百年再闰。 (0[48]|[2468][048]|[13579]...

    C#读取JPEG图片的Exif信息

    returnValue = ParsedDate(Definitions.exifCode.DateTime).ToString(); break; case Definitions.exifCode.WhitePoint: returnValue = WhitePoint(); break; case Definitions.exifCode....

    异步ajax验证用户名(防止重名)

    <%@ WebHandler Language="C#" Class="Handler" %> using System; using System.Web; using System.Data; using DAL; public class Handler : IHttpHandler { public void ProcessRequest (HttpContext context) ...

    tingMailSendSystem--仿OutLook的邮件编辑面板

    string cid = string.Format("image_{0:00}", i); Attachment attach = new Attachment(path); attach.Name = Path.GetFileName(path); attach.ContentId = cid; message.Attachments.Add(attach); body = ...

    随机生成6位图片验证码

    image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); context.Response.ClearContent(); context.Response.ContentType = "image/Jpeg"; context.Response.BinaryWrite(ms.ToArray()); context.Session...

    C#日期时间格式化小结

    为了达到不同的显示效果有时,我们需要对时间进行转化,默认格式为:2007-01-03 14:33:34 ,要转化为其他格式,要用到DateTime.ToString的方法(String, IFormatProvider),如下所示: 代码如下:using System;using ...

    asp.net 文件夸域名传输带进度条

    ScriptManager.RegisterStartupScript(this, typeof(upload_aspx), "progress", string.Format(js, Path.GetFileName(this.fileUpload.FileName), DateTime.Now.ToString("yyyy-MM") + "/" + DateTime.Now.Day + "/...

    C#时间格式大全

    DateTime.ToString的方法(String, IFormatProvider) using System; using System.Globalization; String format="D"; DateTime date=DataTime,Now; Response.Write(date.ToString(format, DateTimeFormat

    C#聊天程序

    return string.Concat(s[0].ToString(), s[1].ToString()); } /// /// 线程执行体,转发消息 /// /// 传递给线程执行体的用户名,用以与用户通信 private void ThreadFunc(object obj) { //通过转发表...

    C# for CSDN 乱七八糟的看不懂

    没法下载,到这里折腾一把试试。 本文由abc2253130贡献 doc文档可能在WAP端浏览... } } 输出格式 简单格式 对于控制台程序: Console.WriteLine("Found {0} Odd Numbers, and {1} Even Numbers.",odd, even) ; 对于...

Global site tag (gtag.js) - Google Analytics