// sql dateselect count([Action]), CONVERT(CHAR(10), [Timestamp], 111) as [SpecificPeriod] from UserAction group by CONVERT(CHAR(10), [Timestamp], 111)
// 时间相减
DateTime dtone = Convert.ToDateTime("2007-1-1 05:32:22"); DateTime dtwo = Convert.ToDateTime("2007-1-1 04:20:15");
TimeSpan span = dtone.Subtract(dtwo); Response.Write(span.Days + "天" + span.Hours + "小时" + span.Minutes + "分钟" + span.Seconds+"秒");
// compare the two date
double unixTime = Convert.ToInt64(codes); var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); DateTime dt = epoch.AddSeconds(unixTime); DateTime now = DateTime.UtcNow; if (dt > now) { return true; }
// 得到当周/当月的第一天/Last Four weeks
// Microsoft Sql Server 中利用Convert 函数转换Datetime 到 Stringusing System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication4 { class Program { static void Main(string[] args) { DateTime thisWe = GetWeekStart(DateTime.Now, 3); DateTime lastTh = thisWe.AddDays(-6); lastTh = Convert.ToDateTime(lastTh.ToString("yyyy-MM-dd 00:00:00")); thisWe = Convert.ToDateTime(thisWe.ToString("yyyy-MM-dd 23:59:59")); Console.WriteLine("the wed is : " + thisWe); Console.WriteLine("the last Th is : " + lastTh); Console.ReadKey(); } /// <summary> /// 获得当周起始日期 贾世义 /// </summary> /// <param name="startDate">提供日期</param> /// <param name="weekStart">周开始(0为周日 1周一 2周二 3周三 4周四 5 周五 6 周六)</param> /// <returns></returns> public static DateTime GetWeekStart(DateTime startDate, int weekStart) { int day = (int)startDate.DayOfWeek; if (day > weekStart) { return startDate.AddDays(weekStart - day); } else if (day < weekStart) { return startDate.AddDays(weekStart - day - 7); } else { return startDate; } } /// <summary> /// 取得某月的第一天 /// </summary> /// <param name="datetime">要取得月份第一天的时间</param> /// <returns></returns> private DateTime FirstDayOfMonth() { DateTime datetime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 00:00:00")); return datetime.AddDays(1 - datetime.Day); } /**/ /// <summary> /// 取得某月的最后一天 /// </summary> /// <param name="datetime">要取得月份最后一天的时间</param> /// <returns></returns> private DateTime LastDayOfMonth() { DateTime datetime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 23:59:59")); return datetime.AddDays(1 - datetime.Day).AddMonths(1).AddDays(-1); } } }
// http://blog.csdn.net/forlinux/article/details/2723694
DateTime总结
最新推荐文章于 2024-02-19 20:36:52 发布