我们在评论中往往会看到多少天前,多少小时前. 实现原理:现在时间-过去时间 得到的时间差来做比较 下面我定义了一个Helper类,大家直接引用即可,参数就是时间差,注意时间差类型是TimeSpan类型,而不是DateTime类型哦~ TimeHelper.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 时间测试 { /// <summary> /
select * from Tickets where ( case when UnloadTime is null then datediff(hh,LoadTime,getdate()) else datediff(hh,LoadTime,UnloadTime) end)>=48 这种方式是可以的 Linq时间差: //linq = linq.Where(x => System.Data.Entity.Core.Objects.EntityFunctions.DiffMillisecond
1. 计算给出两个时间之间的时间差 import datetime as dt # current time cur_time = dt.datetime.today() # one day pre_time = dt.date(2016, 5, 20) # eg: 2016.5.20 delta = cur_time - pre_time # if you want to get discrepancy in days print delta.days # if you want to get