简体   繁体   中英

Convert DateTime Without Adjusting for Time Zone

I'm using the jQuery FullCalendar control and populating a hidden field with the calendar events in a JSON string.

To accomplish this I have to convert the date/times.
The example function I found below passes them in a usable format.
However, it's adjusting the events based on the client time zone.

How do I modify the function below to convert a SQL datetime without adjusting for the client time zone?

I tried removing ToUniversalTime() as suggested on another post, but it throws the time WAY off.

private long ConvertToTimestamp(DateTime value)
{
   long epoch = (value.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
   return epoch;
}

I would try STRING newstring = String.Format("{0:yyyy-MM-dd HH:mm:ss}", yourdatevar); , and make sure the format is the one that you need for the SQL Datetime(I beleive that's it though).

尝试执行以下操作,该操作会将日期格式化为较长的数据时间,这应避免与客户端和其他区域性设置造成混淆。

.ToString("yyyy-MM-dd HH:mm:ss:fff") 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM