2017-09-28 8 views
0

を取得中に外れ1日である私は、SharePointリスト内のフィールドのいずれかにDateTime値を保存しています:日付値が

//request is an entity that has all he fields in the list, I am only showing DueDate in the below code 
    if (txtdatepicker.Text != String.Empty) 
    { 
     DateTime dueDate; 
     if (DateTime.TryParse(txtdatepicker.Text, out dueDate)) 
     { 
      request.DueDate = dueDate;//Output {9/30/2017 12:00:00 AM} 
     } 
    } 

日が正しく期日としてSharePointリストに保存されます。9/30/2017 。私は、この日の値を取得しようとすると、

さて問題は、次のとおりです。

if (LI[Constants.FieldName_ReqLst_DueDate] != null) 
    req.DueDate = (DateTime)LI[Constants.FieldName_ReqLst_DueDate];//Output {9/29/2017 6:30:00 PM} 

私はここに来る出力が保存されている値とは全く異なるものです。 SharPoint DateTime列から正しいDate値を取得するにはどうすればよいですか?

私はDateTime.Parse(Convert.ToString(LI[Constants.FieldName_ReqLs‌​t_DueDate])).ToLocal‌​Time()で試してみましたが、ローカルマシンでうまく動作しますが、サーバーにデプロイされていても動作しません。

答えて

0

サーバーはどこにありますか?サーバーが異なるタイムゾーンにある場合は、ToLocalTime()機能に影響します。

多くのサイトでは、タイムゾーンをユーザープロファイルに関連付け、表示されたすべての日付/時刻をその設定値に変換します。 SharePointサイトの

あなたはこれを試すことができます。

if (LI[Constants.FieldName_ReqLst_DueDate] != null) 
{ 
    // create a time zone object hard coding to local time zone 
    var timeInfo = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); 
    var tempDate = (DateTime)LI[Constants.FieldName_ReqLst_DueDate]; 
    req.DueDate = TimeZoneInfo.ConvertTimeFromUtc(tempDate, timeInfo); 
} 

次に、あなたのサイトを使用して誰もが時間を知っているあなたが設定した時間帯に常にあります。

関連する問題