JodaTime Checking if two times is in a period [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have two times start time and end times and I put it in JodaTime Local time as this :
LocalTime localStartTime = new LocalTime( hoursStartTimeInt, minutesStartTimeInt);
LocalTime localEndTime = new LocalTime( hoursEndTimeInt, minutesEndTimeInt);
I want to compare if these times are between 12:00 - 06:00. please help thanks.

You can create two LocalTime for 12:00 and 06:00 and compare it with your start and end time, like this:
LocalTime localStartTime = new LocalTime( hoursStartTimeInt, minutesStartTimeInt);;
LocalTime localEndTime = new LocalTime( hoursEndTimeInt, minutesEndTimeInt);;
LocalTime twelveTime = new LocalTime(12,0);
LocalTime sixTime = new LocalTime(06,0);
localStartTime.isAfter(twelveTime);
localStartTime.isBefore(sixTime);
localEndTime.isAfter(twelveTime);
localEndTime.isBefore(sixTime);

Related

How to get date and time in below format in java? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
How can I get the current date and time and how can I transfer it into the following String format?
06-04-2020 05:00 PM
After that I need to add few minutes to the date? Please help!
Your answer should look something like this:
String dateTimePattern = "dd-MM-yyyy HH:mm a";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateTimePattern );
LocalDateTime yourDay= LocalDateTime.of(2020, 4, 6, 17, 00);
System.out.println(formatter.format(ZonedDateTime.of(yourDay, ZoneId.of("UTC-5"))));
Please look this up for more info on the available formats.
Date yourDate = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy h:m a");
String formatedDate= sdf.format(yourDate);

Adding days to current date in java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I just want to add the 3 days to the current date and print the new date in hive query using java..
please help me out
Calendar c = Calendar.getInstance();
c.setTime(new Date());
c.add(Calendar.DATE, 3);

When i convert java.util.Date to java.sql.Date i mis the time, can i do that convergance with time? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
java.util.Date tempin = pLabIn.getDate();
System.out.println(tempin);
java.util.Date tempout = pLabOut.getDate();
java.sql.Date labIn = new java.sql.Date(tempin.getTime());
System.out.println(labIn);
java.sql.Date labOut = new java.sql.Date(tempout.getTime());
The first System.out shows "Thu Feb 27 22:50:06 PKT 2014"
and the second "2014-02-27"
So it miss time. I want to take time as well.
Use a java.sql.Timestamp instead.
The toString() implementation for java.sql.Date will only give you the date in the format year-month-day.
This is also precised in the documentation:
Formats a date in the date escape format yyyy-mm-dd.
If you want to keep the time in your print statement, you can use a SimpleDateFormat instead.
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(sdf.format(labIn));

How to get whole Week Date From the Selected Date in Java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
i want to have FirstDay of week and last Day of week into the Date Format means i need whole Week date in java using DateChooser means i need to have that whole Existing week for that date. show how to get it i trying to have that logic.
Please Help me and thank you in advance for your Response..
You can use the Calendar class.
Calendar cal = Calendar.getInstance ();
int dayofWeek = cal.get (Calendar.DAY_OF_WEEK);
cal.add (Calendar.DATE, -1 * (dayofWeek - Calendar.MONDAY));
Date fdow = cal.getTime ();
As the cal object is now modified, just add six to get the last day of the week.
cal.add (Calendar.DATE, 6);
Date ldow = cal.getTime ();
Using the third-party Joda-Time makes it a bit easier.
See the question Get first day of a particular week in Joda-Time? java.

How to convert from one date format to another in Java? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
My input is in the format of Sep 22, 2008 and how to convert it into 9/22/2008 using JAVA?
Do like this
Date date = new SimpleDateFormat("MMM d, yyyy").parse("Sep 22, 2008");
String formattedDate = new SimpleDateFormat("MM/dd/yyyy").format(date);
System.out.println(formattedDate);
output
09/22/2008

Categories

Resources