How to get current date time in SharePoint Site Time Zone

if SharePoint time zone is different from server:

SPWeb currentWeb = SPContext.Current.Web;
DateTime utcDateTime = DateTime.UtcNow;
DateTime locateDate = currentWeb.RegionalSettings.TimeZone.UTCToLocalTime(utcDateTime);


by the way:if query the data with the datetime field, you need consider the time zone using StorageTZ='true' , then the caml will query the data convert date time  to the server time

<Geq><FieldRef Name='SetDate'/><Value Type='DateTime' StorageTZ='true' IncludeTimeValue='FALSE'><Today/></Value></Geq>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章