C# 中Datatime类用法总结
C# 中Datatime类用法总结
收集了一些记录下来,这些有的是从网上找的,有些是自己使用到的:
DateTime dt = DateTime.Now;
dt.ToString();//2005-11-5 13:21:25
dt.ToFileTime().ToString();//127756416859912816
dt.ToFileTimeUtc().ToString();//127756704859912816
dt.ToLocalTime().ToString();//2005-11-5 21:21:25
dt.ToLongDateString().ToString();//2005年11月5日
dt.ToLongTimeString().ToString();//13:21:25
dt.ToOADate().ToString();//38661.5565508218
dt.ToShortDateString().ToString();//2005-11-5
dt.ToShortTimeString().ToString();//13:21
dt.ToUniversalTime().ToString();//2005-11-5 5:21:25
dt.Year.ToString();//2005
dt.Date.ToString();//2005-11-5 0:00:00
dt.DayOfWeek.ToString();//Saturday
dt.DayOfYear.ToString();//309
dt.Hour.ToString();//13
dt.Millisecond.ToString();//441
dt.Minute.ToString();//30
dt.Month.ToString();//11
dt.Second.ToString();//28
dt.Ticks.ToString();//632667942284412864
dt.TimeOfDay.ToString();//13:30:28.4412864
dt.ToString();//2005-11-5 13:47:04
dt.AddYears(1).ToString();//2006-11-5 13:47:04
dt.AddDays(1.1).ToString();//2005-11-6 16:11:04
dt.AddHours(1.1).ToString();//2005-11-5 14:53:04
dt.AddMilliseconds(1.1).ToString();//2005-11-5 13:47:04
dt.AddMonths(1).ToString();//2005-12-5 13:47:04
dt.AddSeconds(1.1).ToString();//2005-11-5 13:47:05
dt.AddMinutes(1.1).ToString();//2005-11-5 13:48:10
dt.AddTicks(1000).ToString();//2005-11-5 13:47:04
dt.CompareTo(dt).ToString();//0
dt.Add(?).ToString();//问号为一个时间段
dt.Equals("2005-11-6 16:11:04").ToString();//False
dt.Equals(dt).ToString();//True
dt.GetHashCode().ToString();//1474088234
dt.GetType().ToString();//System.DateTime
dt.GetTypeCode().ToString();//DateTime
dt.GetDateTimeFormats(''s'')[0].ToString();//2005-11-05T14:06:25
dt.GetDateTimeFormats(''t'')[0].ToString();//14:06
dt.GetDateTimeFormats(''y'')[0].ToString();//2005年11月
dt.GetDateTimeFormats(''D'')[0].ToString();//2005年11月5日
dt.GetDateTimeFormats(''D'')[1].ToString();//2005 11 05
dt.GetDateTimeFormats(''D'')[2].ToString();//星期六 2005 11 05
dt.GetDateTimeFormats(''D'')[3].ToString();//星期六 2005年11月5日
dt.GetDateTimeFormats(''M'')[0].ToString();//11月5日
dt.GetDateTimeFormats(''f'')[0].ToString();//2005年11月5日 14:06
dt.GetDateTimeFormats(''g'')[0].ToString();//2005-11-5 14:06
dt.GetDateTimeFormats(''r'')[0].ToString();//Sat, 05 Nov 2005 14:06:25 GMT
string.Format("{0:d}",dt);//2005-11-5
string.Format("{0:D}",dt);//2005年11月5日
string.Format("{0:f}",dt);//2005年11月5日 14:23
string.Format("{0:F}",dt);//2005年11月5日 14:23:23
string.Format("{0:g}",dt);//2005-11-5 14:23
string.Format("{0:G}",dt);//2005-11-5 14:23:23
string.Format("{0:M}",dt);//11月5日
string.Format("{0:R}",dt);//Sat, 05 Nov 2005 14:23:23 GMT
string.Format("{0:s}",dt);//2005-11-05T14:23:23
string.Format("{0:t}",dt);//14:23
string.Format("{0:T}",dt);//14:23:23
string.Format("{0:u}",dt);//2005-11-05 14:23:23Z
string.Format("{0:U}",dt);//2005年11月5日 6:23:23
string.Format("{0:Y}",dt);//2005年11月
string.Format("{0}",dt);//2005-11-5 14:23:23
string.Format("{0:yyyyMMddHHmmssffff}",dt);
计算2个日期之间的天数差
-----------------------------------------------
DateTime dt1 = Convert.DateTime("2007-8-1");
DateTime dt2 = Convert.DateTime("2007-8-15");
TimeSpan span = dt2.Subtract(dt1);
int dayDiff = span.Days + 1;
计算某年某月的天数
-----------------------------------------------
int days = DateTime.DaysInMonth(2007, 8);
days = 31;
给日期增加一天、减少一天
-----------------------------------------------
DateTime dt =DateTime.Now;
dt.AddDays(1); //增加一天
dt.AddDays(-1);//减少一天
其它年份方法类似...
Oracle SQL里转换日期函数
-----------------------------------------------
to_date("2007-6-6",''YYYY-MM-DD");
to_date("2007/6/6",''yyyy/mm/dd");
如下一组数据,如何查找表里包含9月份的记录:
CGGC_STRATDATE CGGC_ENDDATE
=========================================
2007-8-4 2007-9-5
2007-9-5 2007-9-20
2007-9-22 2007-10-5
SELECT * FROM TABLE
(TO_DATE(''2007/9/1'',''yyyy/mm/dd'') BETWEEN CGGC_STRATDATE
AND CGGC_ENDDATE OR CGGC_STRATDATE >=TO_DATE(''2007/9/1'',''yyyy/mm/dd'')
AND CGGC_ENDDATE<=TO_DATE(''2007/9/30'',''yyyy/mm/dd'') "
OR TO_DATE(''2007/9/30'',''yyyy/mm/dd'') BETWEEN CGGC_STRATDATE
AND CGGC_ENDDATE) ORDER BY CGGC_STRATDATE ASC
C# 中Datatime类用法总结的更多相关文章
- 【转】Android中Application类用法
转自:http://www.cnblogs.com/renqingping/archive/2012/10/24/Application.html Application类 Application和A ...
- Android中Application类用法
Application类 Application和Activity,Service一样是Android框架的一个系统组件,当Android程序启动时系统会创建一个Application对象,用来存储系 ...
- pandas中Timestamp类用法讲解
由于网上关于Timestamp类的资料比较少,而且官网上面介绍的很模糊,本文只是对如何创建Timestamp类对象进行简要介绍,详情请读者自行查阅文档. 以下有两种方式可以创建一个Timestamp对 ...
- C# 中Datetime类用法总结
收集了一些记录下来,这些有的是从网上找的,有些是自己使用到的: DateTime dt = DateTime.Now; dt.ToString();//2005-11-5 13:21:25dt.ToF ...
- CSS中伪类及伪元素用法详解
CSS中伪类及伪元素用法详解 伪类的分类及作用: 注:该表引自W3School教程 伪元素的分类及作用: 接下来让博主通过一些生动的实例(之前的作业或小作品)来说明几种常用伪类的用法和效果,其他的 ...
- C#中timer类的用法
C#中timer类的用法 关于C#中timer类 在C#里关于定时器类就有3个 1.定义在System.Windows.Forms里 2.定义在System.Threading.Timer类 ...
- android中Handle类的用法
android中Handle类的用法 当我们在处理下载或是其他需要长时间执行的任务时,如果直接把处理函数放Activity的OnCreate或是OnStart中,会导致执行过程中整个Activity无 ...
- 标准C++中string类的用法
转自博客园:http://www.cnblogs.com/xFreedom/archive/2011/05/16/2048037.html 相信使用过MFC编程的朋友对CString这个类的印象应该非 ...
- Java中Class类详解、用法及泛化
Java中Class类及用法 Java程序在运行时,Java运行时系统一直对所有的对象进行所谓的运行时类型标识,即所谓的RTTI.这项信息纪录了每个对象所属的类.虚拟机通常使用运行时类型信息选准正确方 ...
随机推荐
- 【一天一道LeetCode】#71. Simplify Path
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- RecyclerView实现瀑布流效果(二)
在上篇中我们知道RecyclerView中默认给我们提供了三种布局管理器,分别是LinearLayoutManager.GridLayoutManager.StaggeredGridLayoutMan ...
- Leetcode_123_Best Time to Buy and Sell Stock III
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/43740415 Say you have an array ...
- Java学习笔记(一)网格袋布局
网格袋布局类似于Win8的Metro布局,用于将组件按大小比例放在不同位置的网格内,各组件的实际大小会随着窗口的改变而改变,但相对位置不变,能够很好的适应屏幕. 通过阅读<21天学通Java&g ...
- SpriteBuilder中CCB精灵对象的Sprite frame为什么有时候不能修改
有时候你会发现CCB中的精灵对象(root节点)的Sprite frame是灰色的,不能修改.因为它是根对象,所以不存在被嵌入其他CCB的情况,那到底是什么原因呢? 可以发现此时的Timeline当前 ...
- 【一天一道LeetCode】#15 3Sum
一天一道LeetCode系列 (一)题目 Given an array S of n integers, are there elements a, b, c in S such that a + b ...
- dos2unix(windows脚本文件放到unix下运行要注意)
在windows下编写的shell脚本文件,直接放到linux下运行,是不行的. infiniDB的倒库脚本文件load.sh,将tbl文件导入infiniDB,怎么运行不成功,不建job.运来,是w ...
- RedHat系列软件管理(第二版) --二进制软件包管理
RedHat系列软件管理 --二进制软件包管理 Linux学习思想-Linux相对与Windows来非常透明,因此,无论是系统,还是软件,都会有本身自带,或者是Man给提供的非常详细的说明/帮助文档, ...
- adb shell后出现error解决方案
解决办法: 解决办法: 1.adb kill-server 2.adb start-server 3.adb remount 4.adb shell 一般情况下都可以在此启动adb相关
- How to Create Modifiers Using the API QP_MODIFIERS_PUB.PROCESS_MODIFIERS
In this Document Goal Solution Example Scripts Steps to verify the creation of modifier(s). ...