calendar

Calendar.getTime() fails with java.lang.IllegalArgumentException:MINUTE for Asia/Singapore timezone

余生颓废 提交于 2020-12-11 00:56:09
问题 Why is this code failing? The purpose was to remove the time part. String dateStr = "1982-01-01"; String timeZoneID = "Asia/Singapore"; DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = dateFormat.parse(dateStr); Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone(timeZoneID)); calendar.setLenient(false); calendar.setTime(date); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0);

Calendar.getTime() fails with java.lang.IllegalArgumentException:MINUTE for Asia/Singapore timezone

a 夏天 提交于 2020-12-11 00:50:26
问题 Why is this code failing? The purpose was to remove the time part. String dateStr = "1982-01-01"; String timeZoneID = "Asia/Singapore"; DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = dateFormat.parse(dateStr); Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone(timeZoneID)); calendar.setLenient(false); calendar.setTime(date); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0);

calendar.getDisplayName returning the wrong day

北战南征 提交于 2020-11-28 08:12:44
问题 Below is my program and it is returning the wrong day name when I enter the related month, date and year. What I am missing here? My Program import java.util.Calendar; import java.util.Locale; import java.util.Scanner; public class TimeTest { public static void main(String[] args) { Scanner in = new Scanner(System.in); String month = in.next(); String day = in.next(); String year = in.next(); System.out.println(getDay(day, month, year)); } private static String getDay(String day, String month