How to get 10 min before & after time from a particular time in android -


im doing datetimepicker app in android.on need 10 min before , after time particular datetime.ex. if user selects "12/12/2010 5:00", need "12/12/2010 4:50" 1 value & "12/12/2010 5:10" 1 value.how + 10min & -10min particular time?

my code:

string datetimebefore ; string datetimeafter; ... private timepickerdialog.ontimesetlistener timepickerlistener = new timepickerdialog.ontimesetlistener() {         public void ontimeset(timepicker view, int selectedhour,                 int selectedminute) {             hour = selectedhour;             minute = selectedminute;              string datetime = new stringbuilder()                     // month 0 based, add 1                     .append(month + 1).append("-").append(day).append("-")                     .append(year).append(" ").append(pad(hour)).append(":")                     .append(pad(minute)).tostring(); 

if datetime has value="12/12/2010 5:00".i need datetimebefore value="12/12/2010 4:50" & datetimeafter value="12/12/2010 5:10". thanks.

update after ops code

public static string gettimebefore10minutes(string currentdate) {          simpledateformat format = new simpledateformat("dd/mm/yyyy hh:mm");         try {             // calendar set current date , time singapore time zone             calendar calendar = new gregoriancalendar(timezone.gettimezone("asia/calcutta"));             calendar.settime(format.parse(currentdate));              //set calendar before 10 minutes             calendar.add(calendar.minute, -10);                  //formatter              dateformat formatter = new simpledateformat("dd/mm/yyyy hh:mm");             formatter.settimezone(timezone.gettimezone("asia/calcutta"));               return formatter.format(calendar.gettime());         } catch (parseexception e) {             // todo auto-generated catch block             e.printstacktrace();         }          return null;     }      public static string gettimeafter10minutes(string currentdate) {          simpledateformat format = new simpledateformat("dd/mm/yyyy hh:mm");         try {             // calendar set current date , time singapore time zone             calendar calendar = new gregoriancalendar(timezone.gettimezone("asia/calcutta"));             calendar.settime(format.parse(currentdate));              //set calendar before 10 minutes             calendar.add(calendar.minute, 10);                  //formatter              dateformat formatter = new simpledateformat("dd/mm/yyyy hh:mm");             formatter.settimezone(timezone.gettimezone("asia/calcutta"));               return formatter.format(calendar.gettime());         } catch (parseexception e) {             // todo auto-generated catch block             e.printstacktrace();         }          return null;     } 

and call

gettimeafter10minutes("12/12/2010 5:00"); gettimebefore10minutes("12/12/2010 5:00"); 

result be

12/12/2010 05:10 12/12/2010 04:50 

read more blog calculate date ranges


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -