Java tutorial
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Calendar; public class Main { private static SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm aa"); public static String getCurrentTimeString(int s) { //s=0 for star time s=1 for end time Calendar currentCalendar = Calendar.getInstance(); int hours = currentCalendar.get(Calendar.HOUR_OF_DAY); int minutes = currentCalendar.get(Calendar.MINUTE); if (minutes < 30) { currentCalendar.setTimeInMillis(currentCalendar.getTimeInMillis() + (30 - minutes) * 60 * 1000); } if (minutes > 30) { currentCalendar.setTimeInMillis(currentCalendar.getTimeInMillis() + (60 - minutes) * 60 * 1000); } if (s == 1) currentCalendar.setTimeInMillis(currentCalendar.getTimeInMillis() + 30 * 60 * 1000); return timeFormat.format(currentCalendar.getTimeInMillis()); } }