How to subtract X day from a Date object in Java?
I want to do something like: Date date = new Date(); // current date date = date – 300; // substract 300 days from current date and I want to use this “date” How to do it? 10 Answers 10
I want to do something like: Date date = new Date(); // current date date = date – 300; // substract 300 days from current date and I want to use this “date” How to do it? 10 Answers 10
I have parsed a java.util.Date from a String but it is setting the local time zone as the time zone of the date object. The time zone is not specified in the String from which Date is parsed. I want to set a specific time zone of the date object. How can I do that? … Read more
I want to convert a java.util.Date object to a String in Java. The format is 2010-05-30 22:15:52 17 Answers 17
I’m using Java’s java.util.Date class in Scala and want to compare a Date object and the current time. I know I can calculate the delta by using getTime(): (new java.util.Date()).getTime() – oldDate.getTime() However, this just leaves me with a long representing milliseconds. Is there any simpler, nicer way to get a time delta? 45 s … Read more
Convert a Date to a String using DateFormat#format method: String pattern = “MM/dd/yyyy HH:mm:ss”; // Create an instance of SimpleDateFormat used for formatting // the string representation of date according to the chosen pattern DateFormat df = new SimpleDateFormat(pattern); // Get the today date using Calendar object. Date today = Calendar.getInstance().getTime(); // Using DateFormat format method we can create a string … Read more