Update Modified Date” for a List Item programmatically
-
2012년 5월 30일 수요일 오전 8:48
Hi All,
I am trying to update “Modified Date” for a List Item programmatically. The issue is that the date gets set to previous date of what I pass. E.g. Value Passed 30/05/2012 gets set to 29/05/2012 23:00:00
Please help!
Ameya
모든 응답
-
2012년 5월 30일 수요일 오전 8:57
Hi,
You could try converting date to UTC before updating, I'd say you're in a +1 timezone.
Please don't forget to mark the post as Helpful if you find my comment useful and as Answer if it solved your problem.
INFOTEHNA Group, Document and Process Management Solutions ( www.infotehna.com ) -
2012년 5월 30일 수요일 오전 9:05
Hi Ameya,
You should convert the specified DateTime value from local time to Coordinated Universal Time (UTC). Take a look at this example SPTimeZone.LocalTimeToUTC Method
Dmitry
Lightning
Tools Check out our SharePoint tools and web parts |
Lightning Tools Blog
- 편집됨 Dmitry KaloshinMicrosoft Community Contributor 2012년 5월 30일 수요일 오전 9:06
-
2012년 5월 30일 수요일 오전 10:09
Hi Mladen and Dmitry,
Thanks for your prompt reply.
I tried the following two methods, but no luck.
Method 1
DateTime selectedDate = DateTime.Parse(txtEffectiveDate.Text);
SPRegionalSettings oRegionalSettings = thisweb.RegionalSettings;
SPTimeZone oTimeZone = oRegionalSettings.TimeZone;
DateTime Effectivedate = oTimeZone.LocalTimeToUTC(selectedDate);Method 2
DateTime Effectivedate = DateTime.Parse(txtEffectiveDate.Text).ToUniversalTime();Date still gets set as - Input 26/05/2012 set as 25/05/2012 17:30:00 , Only time part seems to have changed.
Has to do anything with the date time /regional setting on the server where SharePoint is setup?
- 편집됨 Amey0072 2012년 5월 30일 수요일 오전 10:10
-
2012년 5월 30일 수요일 오전 10:24
Hello, I found this after some googling: http://social.msdn.microsoft.com/Forums/en/sharepointdevelopment/thread/935101ca-fe9c-4f2b-8d81-20eb1dc8f9c8
It appears it is always in GMT, so the answer would then be to set it to your local time after reading it (if you're doing that from code, since apparently SharePoint relies on UI to do that). That would compensate for the time offset in accessing time.
Please don't forget to mark the post as Helpful if you find my comment useful and as Answer if it solved your problem.
INFOTEHNA Group, Document and Process Management Solutions ( www.infotehna.com )- 답변으로 표시됨 Amey0072 2012년 5월 31일 목요일 오전 7:08
-
2012년 5월 30일 수요일 오후 4:31
Hi,
This is a code that might help, it uses the regional settings on your sharepoint website settings . You can convert to UTC or use your local time.
public DateTime GetRegionalSettingsDateTime(DateTime date,SPWeb oWeb) { SPRegionalSettings oRegionalSettings = oWeb.RegionalSettings; SPTimeZone spTimeZone = oRegionalSettings.TimeZone; DateTime utcDateTime = date.ToUniversalTime(); return spTimeZone.UTCToLocalTime(utcDateTime); }

