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.
Unfortunately, activation email could not send to your email. Please try again.

converts date and numbers to string using current locale settings

Thread ID:

Created:

Updated:

Platform:

Replies:

132690 Sep 15,2017 09:38 AM Sep 21,2017 02:35 PM JavaScript 5
loading
Tags: ejCalculate
hui zheng
Asked On September 15, 2017 09:38 AM

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

Mohanraj Gunasekaran [Syncfusion]
Replied On September 18, 2017 08:55 AM

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 
 


hui zheng
Replied On September 18, 2017 09:11 AM

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

Mohanraj Gunasekaran [Syncfusion]
Replied On September 19, 2017 01:14 PM

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 


hui zheng
Replied On September 20, 2017 08:44 AM

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

 


Mohanraj Gunasekaran [Syncfusion]
Replied On September 21, 2017 02:35 PM

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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;