我有我的數據庫服務器位於美國用戶從印度輸入日期必須存儲客戶端而不是服務器。但不幸的是,服務器日期存儲在數據庫中。我只向當天的用戶顯示僅限於當天的條目。 問題是當用戶輸入記錄直到12:30 PM(客戶機)顯示給用戶,但在12:30 PM(客戶機)之後,只有在12:30 PM(客戶機)之後才進行輸入時,顯示任何想法?如何從asp.net中的TimeZone獲取客戶端本地日期?
例如:在2013年6月5日(DD/MM/YYYY),直到12:30 PM做項顯示,當客戶機上的日期是2013年6月5日上午11時57 但是當客戶機日期是2013年6月5日下午12點57分,輸入的條目不會顯示,但顯示下午12點30分之後輸入的條目。在DB上面例如。創建日期存儲爲05/05/2013不知道爲什麼? 在cs文件:
public static DateTime GetIndianDate(DateTime dateTime)
{
return TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dateTime, TimeZoneInfo.Local.Id,"India Standard Time").Date;
}
要僅顯示今天的條目:
shipments = BLL.GetShipmentsByUserIdNDate(userId, Classes.Common.GetIndianDate(DateTime.Now.Date));
public static List<Shipment> GetShipmentsByUserIdNDate(Guid userId, DateTime dateTime)
{
Entities db = new Entities();
List<Shipment> shipments = (from s in db.Shipments
where s.UserId == userId && s.CreatedDate == dateTime
select s).ToList();
return shipments;
}
同時插入:
shipment.CreatedDate = Classes.Common.GetIndianDate(DateTime.Now.Date);
public static DateTime GetIndianDate(DateTime dateTime)
{
return TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dateTime, TimeZoneInfo.Local.Id,"India Standard Time").Date;
}
那麼,如何將存儲客戶機的日期?現在它仍然只存儲服務器日期。
幫助讚賞!
[將UTC日期時間全局轉換爲用戶指定的本地日期時間]可能的副本(http://stackoverflow.com/questions/16345862/globally-convert-utc-datetimes-to-user-specified-local-datetimes) – 2013-05-06 13:47:43