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

converts date and numbers to string using current locale settings

Hello,
we use Javascript's calculate API (CalcQuick()) to parse and compute the formula. The result can be text, number or a date. Is there way to get locale result (when it is a number or date) based on browser's locale settings?

Thanks
Hui

5 Replies

MG Mohanraj Gunasekaran Syncfusion Team September 18, 2017 12:55 PM UTC

Hi Hui, 
 
Thanks for using Syncfusion product. 
 
By default, ejCalcualte does not have the support to localize the formula result values. As ejCalculate has fully designed with the string operations, it will not work based on the localization settings. Calculations will be performed based on the string operations. Hence you should convert the resulted string to their locale settings to get the localized string. 
 
Please let us know if you have any concerns 
 
Regards, 
Mohanraj G 
 



HZ hui zheng September 18, 2017 01:11 PM UTC

Thank you for the reply. 


>>Hence you should convert the resulted string to their locale settings to get the localized string. 

If i know the resulted string is number or date, i can use Date.prototype.toLocaleDateString() or Number.prototype.toLocaleString() to convert it to localized string. But the problem is how can i tell the resulted string is number or date or just normal text?  I cannot simply build Date object from resulted string because strings such as  "1231" and  "20/09/2017" and "Fri sep 15 2017" all will work. Does the result string from date formulas comply with some format, so that i can use regular expression to tell if result string is date or number or just a normal text ?

Thanks
Hui


MG Mohanraj Gunasekaran Syncfusion Team September 19, 2017 05:14 PM UTC

Hi Hui, 
 
Sorry for the inconvenience caused. 
 
We can understand your scenario. By default, ejCalculate returns the result in string format. By default, Date object accepts the number as date in javascript. 
 
In order to find the resulted string as a Date or number, you can use the ej.ParseDate method from ej.Globalize.js script file. Please refer to the following code example, 
 
Code example 
<script src="common/ej.globalize.js">script> 
 
ej.parseDate("1234") 
//Result: null 
 
ej.parseDate("20/09/2017", "dd/mm/yyyy") 
//Result: Fri Jan 20 2017 00:09:00 GMT+0530 (India Standard Time) 
 
ej.parseDate("Fri sep 15 2017", "ddd MMM dd yyyy") 
//Result: Fri Sep 15 2017 00:00:00 GMT+0530 (India Standard Time) 
 
 
 
Note: 
If you use the different culture you can pass that culture in ej.Parse method. Please refer to the below code example, 
 
Code example 
ej.parseDate("20/09/2017","dd/mm/yyyy", “en-US”) 
 
  
 
Regards, 
Mohanraj G 



HZ hui zheng September 20, 2017 12:44 PM UTC

Hi Mohanraj, thank you for the solution. However, it doesn't look to be applicable to our case. The resulted string can be from any formula, so we don't know which format we can use when calling parseDate().

Thanks

Hui

 



MG Mohanraj Gunasekaran Syncfusion Team September 21, 2017 06:35 PM UTC

Hi Hui, 
 
Sorry for the inconvenience caused. 
 
By default, ej Components do not have the support to find the date string without format in javascript. We have posted your query through MSDN. Once we get the proper solution from MSDN, we will update the solution to you. Please refer the following MSDN link for your reference, 
 
Please let us know if you have any concerns. 
 
Regards, 
Mohanraj G 


Loader.
Up arrow icon