Example usage for java.util Calendar AM_PM

List of usage examples for java.util Calendar AM_PM

Introduction

In this page you can find the example usage for java.util Calendar AM_PM.

Prototype

int AM_PM

To view the source code for java.util Calendar AM_PM.

Click Source Link

Document

Field number for get and set indicating whether the HOUR is before or after noon.

Usage

From source file:Main.java

public static boolean isAM(Calendar time) {
    return Calendar.AM == time.get(Calendar.AM_PM);
}

From source file:Main.java

private static boolean isSameAmPm(long start, long end) {
    Calendar starting = calendarByMillis(start);
    Calendar ending = calendarByMillis(end);
    return starting.get(Calendar.AM_PM) == ending.get(Calendar.AM_PM);
}

From source file:Main.java

public static String millisToDate(long currentTime) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currentTime);
    return calendar.get(Calendar.HOUR) + ":" + calendar.get(Calendar.MINUTE) + ":"
            + calendar.get(Calendar.SECOND) + " " + (calendar.get(Calendar.AM_PM) == 0 ? "AM" : "PM");
}

From source file:Main.java

public static Date buildShiftEndTime(int startHour, int startMin, int startAmPm, int endHour, int endMin,
        int endAmPm) {
    endHour = endHour == 12 ? 0 : endHour;

    calendar.clear();//  ww w  . j  a  v a  2s.  com

    calendar.set(Calendar.HOUR, endHour);
    calendar.set(Calendar.MINUTE, endMin);

    calendar.set(Calendar.AM_PM, endAmPm);

    if (startAmPm == Calendar.PM && endAmPm == Calendar.AM) {
        calendar.add(Calendar.DAY_OF_MONTH, 1);
    }

    return calendar.getTime();
}

From source file:Main.java

public static Date buildShiftStartTime(int startHour, int startMin, int startAmPm, int endHour, int endMin,
        int endAmPm) {
    startHour = startHour == 12 ? 0 : startHour;

    calendar.clear();//from   w w w  .  java  2 s .com

    calendar.set(Calendar.HOUR, startHour);
    calendar.set(Calendar.MINUTE, startMin);

    calendar.set(Calendar.AM_PM, startAmPm);

    return calendar.getTime();
}

From source file:Main.java

public static String buildShiftTimeRepresentation(Date shiftTime) {
    calendar.setTime(shiftTime);//from   w ww .  j  av a2 s.com

    String s = "";
    s = format.format(calendar.get(Calendar.HOUR) == 0 ? 12 : calendar.get(Calendar.HOUR));
    s += ":" + format.format(calendar.get(Calendar.MINUTE));
    s += calendar.get(Calendar.AM_PM) == Calendar.AM ? " AM" : " PM";
    return s;
}

From source file:Main.java

public static String getDateFromUTC(long timestamp) {
    if (timestamp == 0)
        timestamp = System.currentTimeMillis();
    Date date = new Date(timestamp);
    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    cal.setTime(date);/*  ww w .j av  a  2 s. com*/
    String val = (cal.get(Calendar.MONTH) + "/" + cal.get(Calendar.DATE) + " " + cal.get(Calendar.HOUR) + ":"
            + cal.get(Calendar.MINUTE) + (cal.get(Calendar.AM_PM) == 0 ? "AM" : "PM"));

    //      final Date currentTime = new Date();
    //      final SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM d, yyyy hh:mm:ss a z");
    //      sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    //      String ret = "UTC time: " + sdf.format(currentTime);
    //      System.out.println(ret);

    return val;
}

From source file:Main.java

/**
 * Takes in a duration in minutes and a start timestamp and returns
 * the formatted time that is timestamp + duration
 *//*  ww  w .  jav  a  2  s  . c  o  m*/
public static String getTimeAfterStart(long startTime, int duration) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(startTime);
    calendar.add(Calendar.MINUTE, duration);

    int minute = calendar.get(Calendar.MINUTE);
    String minuteString = "";
    if (minute < 10)
        minuteString = "0" + minute;
    else
        minuteString = "" + minute;
    String timeString = calendar.get(Calendar.HOUR) + ":" + minuteString + " "
            + AM_PM[calendar.get(Calendar.AM_PM)];
    return timeString;
}

From source file:org.betaconceptframework.astroboa.util.DateUtils.java

public static Calendar clearTimeFromCalendar(Calendar calendar) {
    if (calendar != null) {
        calendar.set(Calendar.HOUR, 0);
        calendar.clear(Calendar.AM_PM); //ALWAYS clear AM_PM before HOUR_OF_DAY
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.clear(Calendar.DST_OFFSET);
        calendar.clear(Calendar.ZONE_OFFSET);
    }// ww w . j ava2  s.c  o m

    return calendar;
}

From source file:com.brayanarias.alarmproject.receiver.AlarmReceiver.java

public static void setAlarms(Context context) {
    //First cancelling all alarms
    cancelAlarms(context);/*from   ww w. ja v  a  2 s .c  om*/
    //Set alarms list
    DataBaseManager dataBaseManager = DataBaseManager.getInstance(context);
    List<Alarm> alarmList = AlarmDataBase.getAlarmList(dataBaseManager);
    int alarmActivatedCount = 0;
    for (Alarm alarm : alarmList) {
        if (alarm.getActivated() == 1) {
            setAlarm(context, alarm);
            alarmActivatedCount++;
        }
    }
    AlarmUtilities.setStatusBarIcon(context, alarmActivatedCount > 0);
    Calendar day = Calendar.getInstance();
    day.set(Calendar.DAY_OF_MONTH, 28);
    day.set(Calendar.MONTH, 8);
    day.set(Calendar.HOUR, 11);
    day.set(Calendar.AM_PM, Calendar.PM);
    if ((day.getTimeInMillis() - Calendar.getInstance().getTimeInMillis()) > 0) {
        setAlarmCumple(context);
    }
}