[aspx.cs]
protected void Page_Load(object sender, EventArgs e) {
if(IsPostBack) {
System.Globalization.CultureInfo.CurrentCulture.ClearCachedData(); //clear the cache
TimeZone localZone = TimeZone.CurrentTimeZone; //Newly selected system time zone will be updated after clearing the cache
}
} |
Hi Shawn,Thanks for contacting Syncfusion Support.We have checked your Query. We suspect that date value does not updated properly after post back due to persistence of previous time zone. So, please clear the cache as mentioned in the below code example to update the browser time zone with System time zone.
[aspx.cs]protected void Page_Load(object sender, EventArgs e) {if(IsPostBack) {System.Globalization.CultureInfo.CurrentCulture.ClearCachedData(); //clear the cacheTimeZone localZone = TimeZone.CurrentTimeZone; //Newly selected system time zone will be updated after clearing the cache}}Reference link: http://stackoverflow.com/questions/296918/net-datetime-now-returns-incorrect-time-when-time-zone-is-changedPlease get back to us if you need further assistance.Regards,Sureshkumar P.
I want the same thing as Shawn and I don't believe that your answer actually works. I don't want the DateTimePicker to do ANYTHING with time zone conversions. Just raw values.
If the user selects 9/9/2017 12:30 PM, I want to enter 9/9/2017 12:30 PM into my database.
I am perfectly fine with raw text. Is this possible?
[sample.aspx.cs]
//dateTime is the ID of the DateTimePicker
var val = dateTime.Value.Value.ToUniversalTime();
//convert dateTime value (object) into UTC |
I tried the solution and ultimately I still have the same problem.
<ej:DateTimePicker ID="dateTime" runat="server" Width="180px"ClientSideOnClose="DateTimeUpdate" ClientSideOnCreate="DateTimeUpdate" ></ej:DateTimePicker>
<ej:Button ID="ButtonNormal" runat="server" Size="Large"OnClick="ButtonNormal_Click" ShowRoundedCorner="true" Text="Post"></ej:Button>
<script>
function DateTimeUpdate(args) {
var serverTimeZoneDiff = +5.5; // Timezone offset with UTC(+5.5 for IST)
var clientTimeZoneDiff = new Date().getTimezoneOffset()/60; // client Time zone offset in hours
var TimezoneOffset = serverTimeZoneDiff + clientTimeZoneDiff;// total time zone offset
this.model.value = new Date(new Date(this.model.value).getTime() + (TimezoneOffset * 60 * 60 * 1000));// updates DateTimePicker value.
this._updateDateTime();// updating DateTimePicker after value change.
}
</script> |
<script>
function create(e){
var serverTimeZoneDiff = +5.5; // Timezone offset with UTC(+5.5 for IST)
var clientTimeZoneDiff = new Date().getTimezoneOffset() / 60; // client Time zone offset in hours
var TimezoneOffset = serverTimeZoneDiff + clientTimeZoneDiff;// total time zone offset
if (isDST(e)) TimezoneOffset = TimezoneOffset - 1;// subracts one hour if daylightsaving enabled.
this.model.value = new Date(new Date(this.model.value).getTime() + (TimezoneOffset * 60 * 60 * 1000));// updates DateTimePicker value.
this._updateDateTime();// updating DateTimePicker after value change.
}
function isDST(e) {
return e.model.value.getTimezoneOffset() < Math.max(new Date(e.model.value.getFullYear(), 0, 1).getTimezoneOffset(), new Date(e.model.value.getFullYear(), 6, 1).getTimezoneOffset());
}
</script> |
<ej:datetimepicker id="dtpOne" runat="server" watermarktext="Select..." width="200px" ClientSideOnCreate="DateTimeUpdate">
<DateTimePickerDrillDown ShowMeridian="False"></DateTimePickerDrillDown>
</ej:datetimepicker>
<ej:datetimepicker id="dtpTwo" runat="server" watermarktext="Select..." width="200px" ClientSideOnCreate="DateTimeUpdate">
<DateTimePickerDrillDown ShowMeridian="False"></DateTimePickerDrillDown>
</ej:datetimepicker>
dtpOne.Value = mynullabledatefromdb.Value ' eq. 2018/01/08 10:00
dtpTwo.Value = Now ' eq. 2018/01/08 11:01
dtpOne.Value = mynullabledatefromdb.Value ' eq. 2018/01/08 10:00
dtpTwo.Value = DateTime.Now ' eq. 2018/01/08 11:01