我有一个日期,我必须检查它是星期六还是星期日。我是否正确的方式?比较两个字符串在java中的日期
Calendar gcal = new GregorianCalendar();
DateFormat dateFormat = new SimpleDateFormat("EEEE");
Date currentDate = gcal.getTime();
String strDate = dateFormat.format(currentDate);
if (!"Saturday".equals(strDate)) {
}
其工作正常。但我不能比较两个字符串一样,
if (!"Saturday" || "Sunday".equals(strDate)) {}
如果日期是星期六或星期天,我必须跳过循环.... 在此先感谢...
您应该使用JDK 8和java.time包。 GregorianCalendar是Java 1.0年份。 – duffymo
[String.equals()具有多个条件(以及对结果的一个操作)]的可能重复](http://stackoverflow.com/questions/10208052/string-equals-with-multiple-conditions-and-one-action- on-result) – Tom
'!'和'||'和其他逻辑运算符的操作数必须是'boolean'。你不能否定'String'! –