function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
moeoomoeoo 

Time zone difference

Hi All
 
I'm trying to create datetime field by C# .Net code.
 
I'm in Australia and time zone is in (GMT+10:00) Eastern Standard Time (New South Wales). The datetime is created on salesforce in different format (Probably US format).
 
For example, my datetime in the database is 29/08/07 but when it is inserted on salesforce, it's being changed to 30/08/07.
 
I found the getServerTimestamp() method but I'm not sure this is the right way to do it and if so, how can I get the datetime inserted right?
 
Thanks in advance
 
Moe
Mike LeachMike Leach
See here.
moeoomoeoo
Thanks a lot. I used your code to save to Salesforce and when I downloaded from salesforce, I used following code.
 
To salesforce,
 
dt = DateTime.Parse(text);
dt = dt.ToUniversalTime();

 

From Salesforce,

public static DateTime ToLocalDateTime(DateTime date)

{

DateTime dtReturn = new DateTime(1900, 1, 1);

try

{

TimeZone objTimeZone = TimeZone.CurrentTimeZone;

TimeSpan objTimeSpan = objTimeZone.GetUtcOffset(new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day));

dtReturn = date.Add(objTimeSpan);

}

catch

{

dtReturn = new DateTime(1900, 1, 1);

}

return dtReturn;

}