Date now = new Date();
String JobReceivedDate= new SimpleDateFormat("yyyy-MM-dd").format(now);
By this I can get today's date. How can I date yesterday date??? I want that to be in string and in the same format. Thanks
How do you get yesterdays' date using JavaScript? We use the setDate() method on yesterday , passing as parameter the current day minus one. Even if it's day 1 of the month, JavaScript is logical enough and it will point to the last day of the previous month.
Try this:
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
dateFormat.format(cal.getTime()); //your formatted date here
You will get the day before always !
try this:
private String getYesterdayDateString() {
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Calendar cal = Calendar.getInstance()
cal.add(Calendar.DATE, -1);
return dateFormat.format(cal.getTime());
}
I mostly use this
Date mydate = new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24));
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
String yestr = dateFormat.format(mydate);
Now you can get date from "yestr"
Similarly for Tomorrow's date you can change first line like this (just change negative sign to positive)
Date mydate = new Date(System.currentTimeMillis() + (1000 * 60 * 60 * 24));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With