Is there anyway to adjust default timezone in code?
I have a global site with sub lists for each region and they are all on different time
Hi
yes provided you have different site have different regional setting.
use this method LocalTimeToUTC()
using (SPSite oSiteCollection = new SPSite("http://localhost")) { using (SPWeb oWebsite = oSiteCollection.AllWebs["Website_Name"]) { SPFileCollection collFiles = oWebsite.Folders["Shared Documents"].Files; SPRegionalSettings oRegionalSettings = oWebsite.RegionalSettings; SPTimeZone oTimeZone = oRegionalSettings.TimeZone; foreach (SPFile oFile in collFiles) { Console.WriteLine(oFile.Title + " :: " + oTimeZone.UTCToLocalTime(oFile.TimeCreated) + " :: " + oTimeZone.UTCToLocalTime(oFile.TimeLastModified) + "<BR>"); } } }
https://dhendry.wordpress.com/2012/06/30/converting-times-utc-to-local-sharepoint/
You can make a simple console application,place this code and run..it should work
I am not overly familiar with how to do this is there a sample you can show?
I am assuming this is the code but not sure how to plug into my .aspx file.
[SecurityPermissionAttribute(SecurityAction.Assert, UnmanagedCode =
true)]
public DateTime UTCToLocalTime(
DateTime date
)
using (SPSite oSiteCollection =
new SPSite("http://localhost"))
{
using (SPWeb oWebsite = oSiteCollection.AllWebs["Website_Name"])
{
SPFileCollection collFiles = oWebsite.Folders["Shared Documents"].Files;
SPRegionalSettings oRegionalSettings = oWebsite.RegionalSettings;
SPTimeZone oTimeZone = oRegionalSettings.TimeZone;
foreach (SPFile oFile
in collFiles)
{
Console.WriteLine(oFile.Title +
" :: " + oTimeZone.UTCToLocalTime(oFile.TimeCreated) +
" :: " + oTimeZone.UTCToLocalTime(oFile.TimeLastModified) +
"<BR>");
}
}
}
Hi
In Aspx file what activity you are performing put the logic where you are binding the control with date time field.
This is the specific piece of code I would like it to impact
<SharePoint:FormField runat="server" id="ff63{$Pos}" controlmode="New" fieldname="TRIAGE_Date" __designer:bind="{ddwrt:DataBind('i',concat('ff63',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@TRIAGE_Date')}" />
Hi Pinkston,
Please refer this link :
http://solutionz4u.blogspot.com/2011/05/creating-simple-console-application-in.html
replace your code in Main()
hope this helps :)
you can also refer this :
http://www.c-sharpcorner.com/UploadFile/0f100d/creating-a-simple-console-application-in-sharepoint-2010/
is there a way to use this
SPTimeZone timeZone = SPContent.Current.Web.RegionalSettings.TimeZone;
listItem[fieldName] = timeZone.LocalTimeToUTC(localTime);
CultureInfo ci = new CultureInfo("en-GB");
SPRegionalSettings rs = new SPRegionalSettings(web, false);
rs.LocaleId = (uint)ci.LCID;
rs.Time24 = rs.GetDefaultTime24((uint)ci.LCID);
rs.CalendarType = (short)rs.GetDefaultCalendarType(ci.LCID);
web.RegionalSettings = rs;
web.Update();
Hi,
If this is a one time activity create a console application and do it.
If not you can write a feature. and write the code.
Code for Site feature can we like this. Also you can write code on the feature deactivation to set some other setting.
SPSite site = properties.parent as SPSite; SPWeb web = site.RootWeb; CultureInfo ci = new CultureInfo("en-GB"); SPRegionalSettings rs = new SPRegionalSettings(web, false); rs.LocaleId = (uint)ci.LCID; rs.Time24 = rs.GetDefaultTime24((uint)ci.LCID); rs.CalendarType = (short)rs.GetDefaultCalendarType(ci.LCID); web.RegionalSettings = rs; web.Update();
Hope this helps. Sorry for the delay!
Ashish,
Does this go right in my ASPX code?
1. You have to open visual studio. > Create Feature (Site Scope) > Write the Code (deploy to site collection)
2. Goto Site Settings > Features > Activate the feature.
--Other Approach-----------------------------------------------------------------------------------
1. Open Visual Studio
2. Create console application > add reference to Dlls (Microsoft.Sharepoint - please note this will run on the sharepoint server - otherwise csom comes into picture)
3. Code
using(SPSite osite = new SPSite("url")) { //rest code from Above. }
>>But wait :) you can do all this from UI as well. If just one time activity on an already deployed site.
Site Setting (on right pannel) > Under Site Administration > Regional Settings