java-calendar

Get timezone of area with country code in Java

限于喜欢 提交于 2021-01-01 02:17:49
问题 I have to pass a message (jms) with timezone info like (America/Los_Angeles) but I have only country name and code. If it possible get timezone info with Java code. Somewhere I read this: System.out.println(TimeZone.getTimeZone("US")); But its giving output as sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null] I am expecting List of "America/Los_Angeles", ... 回答1: As per the documentation the getTimeZone method returns the specified

Get timezone of area with country code in Java

孤街醉人 提交于 2021-01-01 02:15:14
问题 I have to pass a message (jms) with timezone info like (America/Los_Angeles) but I have only country name and code. If it possible get timezone info with Java code. Somewhere I read this: System.out.println(TimeZone.getTimeZone("US")); But its giving output as sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null] I am expecting List of "America/Los_Angeles", ... 回答1: As per the documentation the getTimeZone method returns the specified

Print 12 Month Year and the next 2 Years using Java

房东的猫 提交于 2019-12-23 22:21:13
问题 Already had an initial program for this one, I made the code as much shorter and precise as possible. But upon checking it seems that the next 2 years still prints 2018 and I am expecting 2019 and 2020. How can I possible dynamically prints the year when it shows 2018, 2019, and 2020. might be I am missing some iterations in my code. Also feel free to criticize my code, you can also suggest more shorter codes by using the Calendar API or Java 8 utilities as much as you can. See code below:

getActualMinimum with HOUR as argument of Calendar returns 12 in Java

拥有回忆 提交于 2019-12-17 21:23:47
问题 I'm trying to set the time of the calendar by calling the method calendar.set(Calendar.HOUR, calendar.getActualMinimum(Calendar.HOUR)); But getActualMinimum(Calendar.HOUR) returns 12 instead of 0. 回答1: Try using Calendar.HOUR_OF_DAY . 回答2: tl;dr Use java.time classes rather than the troubled legacy classes. To get the first moment of a day, call LocalDate.atStartOfDay( ZoneId ). LocalDate.now( // Represent the date alone, without time-of-day and without time zone. ZoneId.of( "Africa/Tunis" )

Getting incorrect result when checking a date between two other dates in Java

谁说我不能喝 提交于 2019-12-08 07:55:16
问题 I'm using the code below to check if an hour is between two other specific hours: String openHour = "08:00 AM"; String currentHour = "10:00 PM"; String closeHour = "11:00 PM"; //Change to 02:00 AM doesn't work!!! SimpleDateFormat format = new SimpleDateFormat("hh:mm a"); Date openHourDate = format.parse(openHour); Date currentHourDate = format.parse(currentHour); Date closeHourDate = format.parse(closeHour); Calendar openCalendar = Calendar.getInstance(); openCalendar.setTime(openHourDate);

getActualMinimum with HOUR as argument of Calendar returns 12 in Java

时光毁灭记忆、已成空白 提交于 2019-11-28 14:51:39
I'm trying to set the time of the calendar by calling the method calendar.set(Calendar.HOUR, calendar.getActualMinimum(Calendar.HOUR)); But getActualMinimum(Calendar.HOUR) returns 12 instead of 0. Try using Calendar.HOUR_OF_DAY . tl;dr Use java.time classes rather than the troubled legacy classes. To get the first moment of a day, call LocalDate.atStartOfDay( ZoneId ) . LocalDate.now( // Represent the date alone, without time-of-day and without time zone. ZoneId.of( "Africa/Tunis" ) // Specify the time zone in which to determine the current date. ) .withDayOfYear( 1 ) // Or `.withDayOfMonth(1)

How to get previous 7 dates from a particular date in java?I am getting 7 dates from present date, but I want from particular date

元气小坏坏 提交于 2019-11-28 02:29:41
//explain public class DateLoop { static String finalDate; static String particularDate; public static void main(String[] args) { // TODO Auto-generated method stub SimpleDateFormat sdf = new SimpleDateFormat("d-M-yyyy "); Calendar cal = Calendar.getInstance(); particularDate = "2-1-2018"; // get starting date cal.add(Calendar.DAY_OF_YEAR, -7); // loop adding one day in each iteration for(int i = 0; i< 7; i++){ cal.add(Calendar.DAY_OF_YEAR, 1); finalDate =sdf.format(cal.getTime()); System.out.println(finalDate); //ie, its giving previous 7 dates from present date, but I want //particular date.