`

关于DateTime.toString(stringFormat)的一些简单说明

    博客分类:
  • C#
阅读更多
1.y代表年份,注意是小写的y,大写的Y并不代表年份。如果使用大写,则会原样把字母输出,例如:
DateTime.Now.ToString("YYYYMMdd")

今天是2010年2月20号,则结果是YYYY0220。如果“天”和“秒”使用大写,也会是分别输出“DD”和“SS”
2.M表示月份。
3.d表示日期,注意D无意义。
4.h或H表示小时,h用的是12小时制,H用的是24小时制。
5.m表示分钟。
6.s表示秒。注意S无意义。
分享到:
评论

相关推荐

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

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

    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#源代码public string ProcessTime()

    // Format the current time into a string... sTime = (iHour ) ? "0" + iHour.ToString() : iHour.ToString(); sTime += ":" + ( (iMin ) ? "0" + iMin.ToString() : iMin.ToString() ); sTime += ":" + ( ...

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

    // Format the current time into a string... sTime = (iHour ) ? "0" + iHour.ToString() : iHour.ToString(); sTime += ":" + ( (iMin ) ? "0" + iMin.ToString() : iMin.ToString() ); sTime += ":" + ( ...

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

    有时候我们要对C#时间进行转换,达到不同的显示效果 默认格式为:2005-6-614:33:34 ... Stringformat=”D”; DateTimedate=DataTime,Now; Response.Write(date.ToString(format,DateTimeFormatInfo.InvariantInfo))

    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#.net中巧用ToString()将日期转成想要的格式

    我们要用到: 代码如下:DateTime.ToString的方法(String, IFormatProvider) using System; using System.Globalization; String format=”D”; DateTime date=DataTime,Now; Response.Write(date.ToStrin

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

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

    c#漂亮的小时钟程序

    toolStripStatusLabel1.Text = string.Format("{0}:{1}:{2}", h, m, s); lblTime.Text = GetTime(); } /// /// 若无此方法,时钟也能显示,但要等窗体显示几秒以后表盘才会显示。有了此方法窗体和表盘同时显示...

    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位图片验证码

    /// PicHandler1 的摘要说明 /// public class PicHandler1 : IHttpHandler, IRequiresSessionState { private string mCheckNo = string.Empty; protected ImgBuilder _ImgBuilder = new ImgBuilder(); ...

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

    string sql = string.Format("select * from MIS.JZG_REGISTER_TOTAL where USER_NAME='{0}'", username); DataTable ds = DBHelper.GetDataSet(sql); context.Response.Clear();//清除缓冲区流中所有内容 ...

    C# String Format Tester 1.2

    工具很简单,可以用来测试DateTime、Int16、Int32、Int64、Decimal、Single、Double、Byte、Guid 这几个类型的ToString格式化输出。此工具还集成了一些常用的格式化字符串,使用起来很方便,不用再去查MSDN。

    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 + "/...

    wpf写一个秒表计时器程序

    label1.Content = string.Format("Windows将在 {0} 关机", TimerClass.GetTimeString1(second)); if (second !cbo1.IsEnabled) { ShutDown(); } } int second = 0; private void Button_Click(object ...

    monthCalendar

    string s = String.Format("{0}年{1}月{2}", GetStemBranch(monthCalendar1.TodayDate), GetMonth(monthCalendar1.TodayDate), GetDay(monthCalendar1.TodayDate)); label1.Text = monthCalendar1.TodayDate + "年...

    智能识别收货地址Java.pdf

    } sb.append(String.format("%s=%s", URLEncoder.encode(entry.getKey().toString(), "UTF-8"), URLEncoder.encode(entry.getValue().toString(), "UTF-8") )); } return sb.toString(); } public static void main...

    图书管理系统附数据库

    string bookid = dataGridView1.SelectedRows[0].Cells[0].Value.ToString(); MessageBox.Show(bookid); string sql1 = "update book set number='{0}',bookname ='{1}',press='{2}',price='{3}',dt='{4}'where...

    SN简易视频播放器源码 SNSimpleVideoPlayer.rar

    text.Text = string.Format("{0}{1:00}:{2:00}:{3:00}", "播放进度:", mediaElement.Position.Hours, mediaElement.Position.Minutes, mediaElement.Position.Seconds); 三、注意事项 开发环境为Visual Studio ...

    给图片加水印

    string strsavepath = txtsavepath.Text.ToString(); string strfilepath =textBox1.Text; if (textBox2.Text.Trim() == "") { MessageBox.Show("请输入要显示的文字"); textBox2.Focus(); return; ...

Global site tag (gtag.js) - Google Analytics