我在compareTo中有一个查询。
我有两个名为todaydate和harvest_date的字符串。
值分别为2019-08-25和1901-11-11。
当我比较它们时,根据我的理解,第一个字符不同的UNI代码值应该返回,据我的理解是1。
但是我得到了18分。
请告诉我哪里出错了。
提前谢谢。
Calendar calendar = Calendar.getInstance();
SimpleDateFormat mdformat = new SimpleDateFormat("yyyy-MM-dd");
String todaydate = "Current Date : " + mdformat.format(calendar.getTime());
year_harvest_date=1901;
month_harvest_date=11;
day_harvest_date=11;
String harvest_date=Integer.toString(year_harvest_date)+"-"+
Integer.toString(month_harvest_date)+"-"
+Integer.toString(day_harvest_date);
Log.e("todaydate",todaydate);
Log.e("harvest_date",harvest_date);
Log.e("today",Integer.toString(todaydate.compareTo(harvest_date)));我期望1作为output.However,我得到18。

发布于 2019-08-26 23:09:34
如果调用的值大于传入的参数,则compareTo返回>0。没有承诺的实际值是什么-只是它的==0,>0,或<0。其他任何东西都是特定于实现的,并且可以随时更改。因此,在比较这些字符串时,1、18或1038575都是有效的输出,并且您不能假设它是其中的一个特定字符串。
https://stackoverflow.com/questions/57660295
复制相似问题