We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Why is the date time less than 8 hours?

First I am in China, I am learning syncfusion angular controls.

My datetimepicker binding code as follow:
<ejs-datetimepicker name="startTime" placeholder="{{'starttime'|translate}}" floatLabelType="Auto" [(ngModel)]="a"></ejs-datetimepicker>

After saved to sql server, the date time is less 8 hours, how should I do ?

Before save:


After save:


3 Replies

CI Christopher Issac Sunder K Syncfusion Team October 31, 2018 05:24 PM UTC

Hi Lorryl, 

Thanks for contacting Syncfusion Support. 

We have checked with your query and suspect that this issue may be raised because of assigning a ISO date string value directly (may be UTC converted  value of the component before saving) to the DateTimePicker component obtained from the server instead of assigning a Date object value. If this is your case, then please ensure to convert the UTC string value obtained from the server to a Date object value and then assign the resultant value to the component to overcome this issue at your end.  

If this is not your case, then please get back to us with more information so that we can validate more on this and provide an exact solution for your requirement. 

  1. Format in which the value is assigned to the DateTimePicker component.
  2. Whether date time value is stored as a string or Date time value
  3. Format of date value being sent to the server.
  4. Whether the Z factor from the ISO string is removed before being passed as value to the DateTimePicker component
  5. Code blocks or any issue reproducing sample for explaining your case will be helpful to get more clear information about your issue.
 
Thanks, 
Christo


LO lorryl November 1, 2018 04:15 AM UTC

Sorry, I don't know what should I do.

I bind the datetime as follow:
<ejs-datetimepicker name="startTime" placeholder="{{'starttime'|translate}}" floatLabelType="Auto" [(ngModel)]="row.DocDate">
</ejs-datetimepicker>

Get row data using "this.row = JSON.parse(data)", and Save row data using "JSON.stringify(this.row)". I don't use "moment" to process the row date value.

Should I use "moment" to solve the problem ? Can you give me a demo ?


DL Deepa Loganathan Syncfusion Team November 1, 2018 07:57 PM UTC

Hi Lorryl,  
 
 
Sorry for the inconvenience.  
 
 
We have looked into your query and we suspect that you were trying to set the value of DateTimePicker as String. Setting Date value as an ISO String causes the Date value to be set based on the timezone factor, causing the difference in time while viewing in a client machine that has different timezone.  
 
 
So, we suggest using the Date of type Date time object instead of string values to overcome this issue.  
 
 
Regarding MomentJS 
 
 
Yes, you can even make use of MomentJS to overcome timezone discrepancies. We prepared a sample to showcase the usage of EJDateTimepicker with MomentJS. please check the sample in the below link.  
 
 
 
 
Please let us know if you have any further queries.  
 
 
Regards,  
 
Deepa L. 


Loader.
Live Chat Icon For mobile
Up arrow icon