473,396 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Local time to UTC time?

I am trying to convert my local time into UTC time in my web application, but when I connected with local machine the time is converting into UTC and saving into Database but when I hosted the application the time is not converting into UTC?

This is the mapper I am using
Expand|Select|Wrap|Line Numbers
  1.  
  2. var entity = new SPInvoiceSettingDto();
  3.         entity.Id = model.Id;
  4.         entity.InvoiceMode = model.InvoiceMode;
  5.         entity.InvoiceType = model.InvoiceType;
  6.         entity.GenerationTime = model.GenerationTime == null ? (DateTime?)null : DateTime.Parse(model.GenerationTime).ToUniversalTime();
  7.         entity.InvoiceGenerationPeriod = model.InvoiceGenerationPeriod;
  8.         entity.InvoiceContactId = model.InvoiceContactId;
  9.         entity.MailAt = model.MailAt == null ? (DateTime?)null : DateTime.Parse(model.MailAt).ToUniversalTime();
  10.         entity.InvoiceContactIdList = model.InvoiceContactIdList;
  11.         entity.InvoiceMailPeriod = model.InvoiceMailPeriod;
  12.         return entity;
Jun 1 '17 #1
1 5932
Frinavale
9,735 Expert Mod 8TB
You need to provide the Kind property to the ToUniversalTime method.

The follow method will convert the date properly:
Expand|Select|Wrap|Line Numbers
  1. public static DateTime ChangeToUTCDate(DateTime theDateToChange) 
  2. {
  3.    DateTime localDateTime = DateTime.SpecifyKind(theDateToChange, DateTimeKind.Local)
  4.    DateTime utcDateTime = TimeZoneInfo.ConvertTimeToUtc(localDateTime, TimeZoneInfo.Local);
  5.    return utcDateTime
  6. }
Jun 20 '17 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: pwldev | last post by:
Sorry if this isn't a good place for this question. I have a problem with losing cookie values whenever a user's local machine date/time is behind the date & time of the IIS machine. The login...
0
by: pduncan | last post by:
Hi all, I need to update client machines with the correct time if it is inaccurate. The server I'm using will always have the correct time so I'll be using that as the source of correct time. ...
5
by: rgrandidier | last post by:
I have a SQL table that stores the UTC time for a column, I then want to display the UTC time to the user in their local time. My approach is to have the user set their time zone via their user...
5
by: ECVerify.com | last post by:
I am trying to convert a computers local time to Pacific time, I can get it back to UTC pretty easy but I actually want to convert whatever the local time is on the computer I want to calculate...
4
by: Anony Mous | last post by:
Hi, Is there a function that would allow me to set the local time while the server is running? I can't seem to find anything on this... Thanks, Peter ---------------------------(end of...
3
by: Randall Parker | last post by:
Suppose one has a database of UTC times that are from different dates in the past. The problem with translating those times to a local time is that one does not know for each UTC time whether the...
8
by: Henrik Goldman | last post by:
I have strings like "2006-03-26 21.51" which I would like to convert into time_t. I know that the string is in localtime. So far I've written the following code: time_t...
1
by: davelist | last post by:
I'm guessing there is an easy way to do this but I keep going around in circles in the documentation. I have a time stamp that looks like this (corresponding to UTC time): start_time =...
2
by: ZR | last post by:
Hello, I need to convert a GMT time string to local time. I can fill out a "tm" structure with the GMT time string. Are there any standard C (or OS) time functions that will allow me to do this? ...
2
by: Nikola Skoric | last post by:
I have been trying to find appropriate way to do get local time in "yyyy-mm-dd hh:mm:ss" format, but the best I got is this: datetime.datetime.fromtimestamp(time.mktime(time.localtime())) It seems...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.