是java中的toString()方法。util。日期与地区无关?
try {
SimpleDateFormat strTemp = new SimpleDateFormat("ddMMMyy", Locale.US);
Date reasult = strTemp.parse(input);
String checkDate = reasult.toString().substring(8, 10) + reasult.toString().substring(4, 7) + reasult.toString().substring(26);
if (!checkDate.toUpperCase().equals(input))
return false;
else
return true;
} catch (Exception ex) {
return false;
}
正如API告诉我的那样,java。util。日期toString()类似于格式“dow mon dd hh:mm:ss zzz yyyy”,我只想知道当windows区域设置更改时,toString()的内容格式是否会更改?如“俄语”、“英语”,建议输入相同,检查日期值是否相同?谢谢你的帮助
# 1 楼答案
通常
toString()
负责转换为字符串。本地系统上的区域设置更改是什么并不重要它会自动与您的区域设置一起工作。上述代码也可以正常工作
# 2 楼答案
Date.toString()
与区域设置无关。您所能观察到的最重要的变化是时区,这取决于计算机的时区设置。这是by design# 3 楼答案
它不会因其区域设置独立而更改。过去有
toLocaleString()
,但现在已经不推荐了你可以看到代码-
# 4 楼答案
小心时区!除此之外,不,它不会根据区域设置而改变。检查源代码(这总是一个好主意!)对于
java.util.Date.toString()
方法:wtb是一个私有的最终静态字符串:
所以,不,它不会改变,它永远是英文名字
更新:正如@nhahtdh指出的,时区将根据计算机区域配置的设置而变化