I am having confusion on understanding the following piece of code:
public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String parsingDate = "२०२४-११-३० १२:५१:४६";
try {
Date date = sdf.parse(parsingDate);
System.out.println("Date " + date);
} catch (ParseException e) {
e.printStackTrace();
}
}
The value stored in parsingDate "२०२४-११-३० १२:५१:४६" is Nepali language equivalent of "2024-11-30 12:51:46".
I assumed that the above piece of code would throw an exception, but to my surprise, the code works perfectly. The output of the program is Sat Nov 30 12:51:46 NPT 2024
How does it work?
Character.getNumericValue('२') == 2)withLocale()!=localizedBy()(also explained in previous comment) - to set the decimal style,localizedBy()should be used (as documented)DecimalStyle.getZeroDigit()is used to convert digits to number [ just subtracted from thechar{ no code point <yet?> } ] )