I have a variable
String date = "10.11.2016"; how do i convert it to
String date = "09.11.2016"; It needs to be done for any date. How can this be realized?
First you need to get an idea of a given date as a class object that is designed to work with dates. This class is the Calendar class.
Get an instance of the Calendar class:
Calendar calendar = Calendar.getInstance(); Create an object that converts the date as a string (of a specific format) into a Date object:
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy"); Get the object of class Date from your string and initialize it with calendar :
calendar.setTime(sdf.parse(date)); Change the calendar object by decrementing the date:
calendar.add(Calendar.DATE, -1); You get the text view of the calendar object:
date = sdf.format(calendar.getTime()); Source: https://ru.stackoverflow.com/questions/592403/
All Articles