var x = 3500;
var y = x.momentJSApi("hindi");
console.log(y);//y = ३,५००
Expected :- ३,५००(based on locale the y value should change)
Want to support number localization.
Related
I use momentJS for date conversion but recently ran into a problem that appears only on iOS when calculating the difference between 2 dates.
I have two strings that looks like this:
const startDate = "08-21-2022 10:28 AM";
const endDate = "08-31-2022 10:28 AM";
In a non iOS system this works:
moment(endDate).diff(moment(startDate), "days")
But on iOS it returns NaN with a warning:
Deprecation warning: value provided is not in a recognized RFC2822 or
ISO format. moment construction falls back to js Date(), which is not
reliable across all browsers and versions. Non RFC2822/ISO date
formats are discouraged and will be removed in an upcoming major
release. Please refer to
http://momentjs.com/guides/#/warnings/js-date/ for more info.
...
I tried the following but without success:
var test1 = moment(dateString);
var test2 = moment(dateString2);
console.log(test2.diff(test1, "days"));
var test5 = moment(dateString).toISOString();
var test6 = moment(dateString2).toISOString();
console.log(moment(test6).diff(moment(test5), "days"));
console.log(moment(dateString).valueOf());
They all seem to return NaN. What can I do to calculate the difference? Even console.log(new Date())
What seems to work is this:
var test3 = moment([2007, 0, 29]);
var test4 = moment([2007, 0, 28]);
test4.diff(test3, "days");
But I'm unsure how I could safely extract the year, I tried these:
var test7 = moment(dateString).year();
console.log("5", test7);
var test8 = moment(dateString).toISOString();
console.log("6", moment(test8).year());
But they all returned NaN;
I have a codesandbox to test on iPhone https://codesandbox.io/s/lively-framework-622p7r?file=/src/App.js
I have a date in string format as:
var x = '2017-07-11 12:00';
var timeZone = 'America/New_York'
Now how can I format date according to timeZone? What I am expecting is:
var y = someMagicalFunction(x,timeZone)
// y = '2017-07-10 14:30'
Also reverse of it:
var x = reverseOfMagicalFunction(y, 'Asia/Kolkata');
// x = '2017-07-11 12:00';
I have used moment.tz to get results when x was of type Date.
var x1 = x.toISOString();
var y = moment.utc(x).tz(timezone).format('YYYY/MM/DD hh:mm:ss');
but was not able to get ReverseMagicalFucntion in that case. Any help?
When you are using momentjs, you can try something like (Check Here):
moment(date).tz('Europe/Berlin').format(format);
Anybody can tell me what's wrong with this code and explain it?
open System
let hexarea t:float =
(3.0*Math.Sqrt(3.0)/2.0) * Math.Pow(t, 2.0)
let value = float (Console.ReadLine())
let calc = hexarea value
printfn "%f" calc
I can give a hint, that when it's like
open System
let hexarea t : float =
(3.0 * Math.Sqrt(3.0) / 2.0) * Math.Pow(t,2.0)
[<EntryPoint>]
let main argv =
let value = float (Console.ReadLine())
let calc = hexarea value
printf "%f" calc
0
Then it works.
Please clarify to me what's happening and what's the problem with the first code.
also, if I remove 0 from the last line, it's complaining ..
If you are getting "Input String was not in a correct format" exception as the title of your question suggests, this is likely because the number you are entering in the Console.ReadLine is not in the correct format.
This is a continuous pain-point if you're from a country that uses decimal comma rather than decimal dot. In Czech, we write 3,14 and so if you set the current culture to cs-CZ you get:
System.Threading.Thread.CurrentThread.CurrentCulture <-
System.Globalization.CultureInfo.GetCultureInfo("cs-CZ")
float "1.0" // Works because this uses invariant culture
System.Double.Parse("1.0") // Fails because this uses cs-CZ culture now
float "1,0" // Fails because the invariant culture requires .
System.Double.Parse("1,0") // Works according to cs-CZ culture
For my math question app I have two random numbers generated then I have 4 buttons as answers. I want to check the answer if the user pushes the right button but it seems not to work.
num1 and num2 are the labels which the random numbers are generated in so technically
num1.text = "(randomnum1)"
and num2.text = "(randomnum2)" Thanks.
I have the following code under button1 IBaction
var sum = (num1) + (num2)
if btn1.titleLabel = (sum){
check.text = "right"
}
Maybe you should do some convert before you add num1 and num2. (convert strings to integers before adding them up, also, you should convert string to integer fisrt when comparing sum and btn.titleLabel)
you have two options:
if btn1.titleLabel.toInt()! == sum
or
if btn1.titleLabel == String(sum)
consider the difference between = (assign) and == (is equal)
to assign a number to a label use
num1.text = "\(randomnum1)"
I recommend to use backing Int variables like randomnum1 to hold the random numbers which can used for the math for example
var randomnum1 = 0, randomnum2 = 0 // instance variables of the class
randomnum1 = randomFuntion()
randomnum2 = randomFuntion()
num1.text = String(randomnum1)
num2.text = String(randomnum2)
now the labels contain the string values of the random numbers, but you can do the math with the associated variables.
var sum = randomnum1 + randomnum2
after that you can check the result as mentioned above
if btn1.titleLabel == String(sum) {
check.text = "right"
}
I have an array that is created like this in Swift
class TableViewCell: UITableViewCell, TKChartDelegate {
var xAxisDates = [] --> filled with fetch from Coredata
var yAxisValues = [] --> filled with fetch from Coredata
var maximumValue = maxElement(yAxisValues) -> error: TableViewCell.Type' does not have a member named 'yAxisValues'
func chart (){
var dataPointSeries = [TKChartDataPoint]()
for var i = 0; i < xAxisDates.count; ++i {
dataPointSeries.append(TKChartDataPoint(x: xAxisDates[i], y: yAxisValues[i]))
println(dataPointSeries)
}
<--more code setting up the chart-->
}
The console output is this:
[x = '2014-11-25 02:00:00 +0000', y = '61', name = '(null)', x = '2014-11-25 02:00:00 +0000', y = '57', name = '(null)']
I would like to find the max and min value of the y's.
I have tried maxElement(dataPointSeries(x)), but that does not work. Any idea how I could do this? I can't seem to find any solution.
All you want is the minimum and maximum values of the y elements, there is no need to consider this in the context of the multi-dimensional array. All you need do is:
let minimumYValue = minElement(yAxisValues)
let maximumYValue = maxElement(yAxisValues)