时间处理总结(一).net

不断整理中。。。

获取当前时间
DateTime.Now.ToString("d") ;//获取到的日期格式为eg :2013/11/14

时间格式只取年月日
DateTime.Now.ToShortDateString(); //2013/11/14

获取年份/月份
DateTime.Now.Year.ToString();2013
DateTime.Now.Month.ToString();08

时间比较
DateTime.Now.CompareTo(data.GDRQ)>=0

时间搓与日期相互转换
1.日期转时间搓
public static DateTime DateTimeToInt(DateTime datetime)
{
return (datetime.ToUniversalTime().Ticks - new DateTime(1970, 1, 1).Ticks) / 10000000
}
2.时间搓转日期
public static DateTime IntToDateTime(int timestamp)
{
return TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970,1,1)).AddSeconds(timestamp);
}

posted @ 2016-07-26 14:59  garsonguo  阅读(148)  评论(0编辑  收藏  举报