`
zhangshenqiu
  • 浏览: 9131 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
最近访客 更多访客>>
社区版块
存档分类
最新评论

DateTime的一些使用方法

F# 
阅读更多

1、DateTime 数字型
System.DateTime currentTime=new System.DateTime();
1.1 取当前年月日时分秒
currentTime=System.DateTime.Now;
1.2 取当前年
int 年=currentTime.Year;
1.3 取当前月
int 月=currentTime.Month;
1.4 取当前日
int 日=currentTime.Day;
1.5 取当前时
int 时=currentTime.Hour;
1.6 取当前分
int 分=currentTime.Minute;
1.7 取当前秒
int 秒=currentTime.Second;
1.8 取当前毫秒
int 毫秒=currentTime.Millisecond;
(变量可用中文)

1.9 取中文日期显示——年月日时分
string strY=currentTime.ToString("f"); //不显示秒

1.10 取中文日期显示_年月
string strYM=currentTime.ToString("y");

1.11 取中文日期显示_月日
string strMD=currentTime.ToString("m");

1.12 取中文年月日
string strYMD=currentTime.ToString("D");

1.13 取当前时分,格式为:14:24
string strT=currentTime.ToString("t");

1.14 取当前时间,格式为:2003-09-23T14:46:48
string strT=currentTime.ToString("s");

1.15 取当前时间,格式为:2003-09-23 14:48:30Z
string strT=currentTime.ToString("u");

1.16 取当前时间,格式为:2003-09-23 14:48
string strT=currentTime.ToString("g");

1.17 取当前时间,格式为:Tue, 23 Sep 2003 14:52:40 GMT
string strT=currentTime.ToString("r");

1.18获得当前时间 n 天后的日期时间
DateTime newDay = DateTime.Now.AddDays(100);

分享到:
评论

相关推荐

    C#中DateTime的使用方法

    C#的datetime使用方法,内容比较详细,例子很典型。

    时间字符串转换成日期对象datetime的方法

    您可能感兴趣的文章:sql语句中如何将datetime格式的日期转换为yy-mm-dd格式将WMI中的DateTime类型转换成VBS时间的函数代码LINQ字符串向datetime 转换时失败的处理方法Sql中将datetime转换成字符串的

    LINQ TO EF 从string 转DateTime不能使用ConvertToDateTime的办法

    担心以后找不到了,留着文档以备查。本方法用于解决linq to EF中从string转成DateTime时不能使用LINQ的ConvertToDateTime的情况。仅用于备查。

    基于DateTime.ParseExact方法的使用详解

    本篇文章是对DateTime.ParseExact方法的使用进行了详细的分析介绍,需要的朋友参考下

    Python datetime模块使用方法小结

    主要介绍了Python datetime模块使用方法小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

    总结PHP中DateTime的常用方法

    实例化对象前面加\表示的是,在命名空间中使用原生的类,如果没有使用命名空间的话,可以把前面的\给删除掉 1. 输出当前时间 $datetime = new \DateTime; print_r($datetime->format('Y-m-d H:i:s')); 2. 输出给定...

    C#中比较常用的DateTime结构的使用方法

    下面就看看一些常用的方法。 首先,DateTime是一个struct。很多时候,会把它当成一个类。但它真的不是,MSDN上的描述如下: DateTime结构:表示时间上的一刻,通常以日期和当天的时间表示。语法: ...

    使用DateTime的ParseExact方法实现特殊日期时间的方法详解

    今天遇到一个特别的需求,...搜索了之后,我找到了下面的方法: 代码如下:public static DateTime ParseExact( string s, string format, IFormatProvider provider)使用例子如下: 代码如下:var dateTimeStr = “07

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

    1.绑定时格式化日期方法: <ITEMSTYLE WIDTH= "18% " > 2.数据控件如DataGrid/DataList等的件格式化日期方法: e.Item.Cell[0].Text = Convert.ToDateTime(e.Item.Cell[0].Text).ToShortDateString(); 3.用String...

    python3_系统时间调用_datetime模块

    datetime模块使用案例源码、# 得到当前日期时间(两种方法)、# 得到当前日期 # 得到当前时间 # 得到当前年份用year_变量接收 # 得到当前月份用month_变量接收 # 得到当前天用day_变量接收 # 使用-拼接年月日得到...

    Yii2中datetime类的使用

    以前更改时间格式的时候经常使用date方法,后来知道php竟然自带datetime类处理时间格式,记录一下用法,方便以后使用 实例化 在yii 1.1中,可以直接写成 $datetime = new DateTime; 但是在yii2 这么写就直接报错...

    LINQ字符串向datetime 转换时失败的处理方法

    今天在使用LINQ时,由于数据库中的时间保存的是varchar()格式,查询时需要比较时间先后,于是使用了: 代码如下:from j in system.jhzdwhere j.dwbm.ToString().Trim() == branchcode.ToString().Trim()&& Convert....

    将python的datetime转换为unix时间戳code.txt

    将python的datetime转换为unix时间戳 13位时间戳获取方法 将unix时间戳转换为python的datetime

    winform dateTime数据类型转换方法

    数据库中保存日期为NULL 程序中查出来判断的时候提示如下: ...C# winfrom中关於datetime数据类型转换问题,提示无法将字符型转换成datetime 数据库中有个字段date,数据类型是datetime,格式为“2013-03-03 00:00:00

    python使用datetime模块计算各种时间间隔的方法

    主要介绍了python使用datetime模块计算各种时间间隔的方法,实例分析了Python使用datetime模块进行各种常用的时间操作技巧,具有一定参考借鉴价值,需要的朋友可以参考下

Global site tag (gtag.js) - Google Analytics