DateTime.ToString(string format)功能很强大,能输出不同格式的日期。以下把一些情况罗列出来,供大家参考。
- y代表年份。注意是小写的y,大写的Y并不代表年份。
- M表示月份。注意是大写的M,小写的m表示分钟。
- d表示日期。注意是小写的d,大写的D并不代表日期。
- h或H表示小时,注意h用的是12小时制,H用的是24小时制。
- m表示分钟。注意是小写的m,大写的M表示月份。
- s表示秒。注意大写的S并不代表秒。
以上所有罗列出来的格式会随着操作系统的不同和格式字符的个数不同而输出相应不同的格式。
分享到:
相关推荐
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()...
String.Format( "yyyy-MM-dd ",yourDateTime); 4.用Convert方法转换日期显示格式: Convert.ToDateTime("2005-8-23").ToString ("yyMMdd",System.Globalization.DateTimeFormatInfo.InvariantInfo); //支持繁体...
有时候我们要对C#时间进行转换,达到不同的显示效果 默认格式为:2005-6-614:33:34 如果要换成成200506,06-2005,2005-6-6或更多的该怎么办呢 我们要用到:DateTime.ToString的方法(String,IFormatProvider) 代码如下:...
数字时钟,动态显示当前时间,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#源代码 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#时间/日期函数大全 有时候我们要对时间进行转换,达到不同的显示效果 默认格式为:2005-6-6 14:33:34 如果要换成成200506,06-2005,2005-6-6或更多的该怎么办呢? 我们要用到: 代码如下:...
比较实用的c#小程序,小时钟 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; //...
之前曾经上传过一个农历处理类,但遇到... 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是一个用来测试字符串格式化输出的小工具。工具很简单,可以用来测试DateTime、Int16、Int32、Int64、Decimal、Single、Double、Byte、Guid 这几个类型的ToString格式化输出。此工具还集成了...
有时候我们要对时间进行转换,达到不同的显示效果 默认格式为:2005-6-6 14:33:34 如果要换成成200506,06-2005,2005-6-6或更多的该怎么办呢 我们要用到:DateTime.ToString的方法(String, IFormatProvider) using ...
richTextBox2.Text += string.Format("{0:0000}", i) + "\n"; } } 根据闰年的规则,很容易整理出规则,四年一闰; ([0-9]{2}(0[48]|[2468][048]|[13579][26]) 百年不闰,四百年再闰。 (0[48]|[2468][048]|[13579]...
returnValue = ParsedDate(Definitions.exifCode.DateTime).ToString(); break; case Definitions.exifCode.WhitePoint: returnValue = WhitePoint(); break; case Definitions.exifCode....
<%@ WebHandler Language="C#" Class="Handler" %> using System; using System.Web; using System.Data; using DAL; public class Handler : IHttpHandler { public void ProcessRequest (HttpContext context) ...
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 = ...
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); context.Response.ClearContent(); context.Response.ContentType = "image/Jpeg"; context.Response.BinaryWrite(ms.ToArray()); context.Session...
为了达到不同的显示效果有时,我们需要对时间进行转化,默认格式为:2007-01-03 14:33:34 ,要转化为其他格式,要用到DateTime.ToString的方法(String, IFormatProvider),如下所示: 代码如下:using System;using ...
ScriptManager.RegisterStartupScript(this, typeof(upload_aspx), "progress", string.Format(js, Path.GetFileName(this.fileUpload.FileName), DateTime.Now.ToString("yyyy-MM") + "/" + DateTime.Now.Day + "/...
DateTime.ToString的方法(String, IFormatProvider) using System; using System.Globalization; String format="D"; DateTime date=DataTime,Now; Response.Write(date.ToString(format, DateTimeFormat
return string.Concat(s[0].ToString(), s[1].ToString()); } /// /// 线程执行体,转发消息 /// /// 传递给线程执行体的用户名,用以与用户通信 private void ThreadFunc(object obj) { //通过转发表...
没法下载,到这里折腾一把试试。 本文由abc2253130贡献 doc文档可能在WAP端浏览... } } 输出格式 简单格式 对于控制台程序: Console.WriteLine("Found {0} Odd Numbers, and {1} Even Numbers.",odd, even) ; 对于...