Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- public class Main {
- public static void main(String[] args) {
- // SimpleDateFormat code12Hours = new SimpleDateFormat("HH:mm"); // 24 hour format
- SimpleDateFormat code12Hours = new SimpleDateFormat("hh:mm"); // 12 hour format
- Date dateCode12 = null;
- String formatTwelve;
- String results;
- String[] date = {"01:11","23:11","13:12","07:01", "00:00", "12:00", "11:59"};
- for (String res: date) {
- try {
- dateCode12 = code12Hours.parse(res); // 12 hour
- } catch (ParseException e) {
- e.printStackTrace();
- }
- formatTwelve = code12Hours.format(dateCode12); // 12
- if (formatTwelve.equals(res)) {
- results = formatTwelve + " AM";
- } else {
- results = formatTwelve + " PM";
- }
- System.out.println(res + " : " + results);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement