after the datetime type is passed into Asp.net Ajax, the time will change to the zero time zone. In other words, the time is 8 hours less than that in China.
example:
Custom type myorder
for more information about using custom types in Asp.net Ajax, see
using ASP. net Ajax asynchronous call of class methods in Web Services and pages (6): automatic conversion of server and client data types: complex types
C #
public class myorder ()
{< br> Public myorder ()
{< BR >}< br>
private datetime _ orderdatetime;
Public datetime orderdatetime
{
Get
{
Return _ orderdatetime;
}
Set
{
_ Orderdatetime = value;
}
}
............ Others
}
JS
Function ()
{
VaR order = new myorder ();
Myorder. orderdatetime = new date ();
............ Others
}
Then, check in WebService. After the input, orderdatetime is less than 8 hours.
If you directly input SQL into the database using the datetime parameter, the normal time is returned.
At last, we found a problem with the time zone.
The solution is to call the tolocaltime () method of datetime. If the time zone of the Local Computer is set correctly, the returned time zone is also correct.
Some materials have been queried, and 8 hours can be added directly. However, the input time includes the time zone information. It seems better to use tolocaltime. In addition, I tried to set web. config to <globalization culture = "ZH-CN" enableclientbasedculture = "false"/> but it does not work.
About tolocaltime
Converts the value of the current datetime object to the local time.
Namespace:System
ProgramSet:Mscorlib (in mscorlib. dll)
Syntax
C # |
PublicDatetimeTolocaltime() |
Return Value
OneDatetimeObject whose kind attribute is And its value is equivalent to the currentDatetimeThe local time of the object value. If the converted value is too largeDatetimeIf the converted value is too small, it cannot be expressedDatetimeMinvalue.Remarks
The local time is equal to the UTC time plus the UTC offset. For more information about the UTC offset, see timezone. getutcoffset. The conversion should also be applied to the currentDatetimeThe daylight saving time rule of the time indicated by the object.
Starting from. NET Framework 2.0,TolocaltimeThe value returned by the method isDatetimeObjectKindConfirm the property. The following table describes possible values.
Kind |
Result |
|
DatetimeIs converted to local time. |
Local |
No conversion is performed. |
|
Assume thatDatetimeThe instance is UTC time, andKindAsUTC. |
The value returned by this conversion isKindAttribute always returnsLocalOfDatetime. Therefore, even ifTolocaltimeApply to the sameDatetime, The returned result is still valid.
This method always uses the local time zone for calculation.