DateTime总结

// sql date
select 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
using 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);
	        }
    }
}
// Microsoft Sql Server 中利用Convert 函数转换Datetime 到 String

// http://blog.csdn.net/forlinux/article/details/2723694



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值