我有一个约会,我必须检查是星期六还是星期天.我正在进行吗?
Calendar gcal = new GregorianCalendar();
DateFormat dateFormat = new SimpleDateFormat("EEEE");
Date currentDate = gcal.getTime();
String strDate = dateFormat.format(currentDate);
if (!"Saturday".equals(strDate)) {
}
Run Code Online (Sandbox Code Playgroud)
它的工作正常.但我不能比较两个字符串,
if (!"Saturday" || "Sunday".equals(strDate)) {}
Run Code Online (Sandbox Code Playgroud)
如果约会是星期六或星期日,我必须跳过循环....提前感谢...
无需创建/格式化Date对象,使用Calendar方法:
Calendar gcal = new GregorianCalendar();
if (gcal.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY && gcal.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
84 次 |
| 最近记录: |