Example usage for java.util Calendar DATE

List of usage examples for java.util Calendar DATE

Introduction

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

Prototype

int DATE

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

Click Source Link

Document

Field number for get and set indicating the day of the month.

Usage

From source file:frk.gpssimulator.service.impl.DefaultGpsdService.java

@Override
public void updatePosition(PositionInfo position) {

    // an NMEA RMC position sentence (report) is of form:
    // $GPRMC,124426,A,5920.7019,N,02803.2893,E,,,121212,,

    Calendar cal = Calendar.getInstance();
    Integer hour = cal.get(Calendar.HOUR_OF_DAY);
    Integer minute = cal.get(Calendar.MINUTE);
    Integer second = cal.get(Calendar.SECOND);
    Integer date = cal.get(Calendar.DATE);
    Integer month = cal.get(Calendar.MONTH) + 1; // java Calendar month
    // starts at 0
    Integer year = cal.get(Calendar.YEAR) % 100; // convert to 2 digit year

    String sHour = String.format("%02d", hour);
    String sMinute = String.format("%02d", minute);
    String sSecond = String.format("%02d", second);
    String sDate = String.format("%02d", date);
    String sMonth = String.format("%02d", month);
    String sYear = String.format("%02d", year);

    String sentence = null;/* w  w  w. j  ava 2  s. co m*/
    if (position == null) {
        sentence = "$GPRMC," + sHour + sMinute + sSecond + ",A,,,,,,," + sDate + sMonth + sYear + ",,";
    } else {
        double lat = position.getPosition().getLatitude();
        double lon = position.getPosition().getLongitude();

        String latSuffix = "N";
        if (lat < 0) {
            latSuffix = "S";
        }
        lat = Math.abs(lat);
        String lonSuffix = "E";
        if (lon < 0) {
            lonSuffix = "W";
        }
        lon = Math.abs(lon);

        long latDeg = (long) lat; // degree part
        double latMin = (lat - latDeg) * 60; // minute part
        long latMinWhole = (long) latMin; // whole part of minute
        Double latMinFrac = latMin - latMinWhole; // fractional part of
        // minute
        String sLatDeg = String.format("%02d", latDeg);
        String sLatMinWhole = String.format("%02d", latMinWhole);
        String sLatMinFrac = latMinFrac.toString().replace("0.", ".");
        long lonDeg = (long) lon; // degree part
        double lonMin = (lon - lonDeg) * 60; // minute part
        long lonMinWhole = (long) lonMin; // whole part of minute
        Double lonMinFrac = lonMin - lonMinWhole; // fractional part of
        // minute
        String sLonDeg = String.format("%02d", lonDeg);
        String sLonMinWhole = String.format("%02d", lonMinWhole);
        String sLonMinFrac = lonMinFrac.toString().replace("0.", ".");

        sentence = "$GPRMC," + sHour + sMinute + sSecond + ",A," + sLatDeg + sLatMinWhole + sLatMinFrac + ","
                + latSuffix + "," + sLonDeg + sLonMinWhole + sLonMinFrac + "," + lonSuffix + ",,," + sDate
                + sMonth + sYear + ",,";
    }

    try {
        pipeWriter.write(sentence + "\r\n");
        pipeWriter.flush();
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.blockcharts.TimeBlockChart.java

public static Date addDay(Date date) {
    //TODO you may want to check for a null date and handle it.
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);// www .j a v  a2 s .c o m
    cal.add(Calendar.DATE, 1);
    return cal.getTime();
}

From source file:org.wiztools.commons.DateUtil.java

/**
 * Adds the number of days to the date and returns the new Date instance.
 * @param date Input date./*ww w .  j a v a  2 s  .co  m*/
 * @param months Number of days to add.
 * @return Computed date.
 */
public static Date getDatePlusDays(final Date date, final int days){
    return getDatePlus(Calendar.DATE, date, days);
}

From source file:com.fluke.util.Util.java

public static String addDate(Date date, int noOfDays) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);//from  w  w w. j  av  a2 s  .  c o  m
    c.add(Calendar.DATE, noOfDays); // Adding 5 days
    return getDate(c.getTime());

}

From source file:in.flipbrain.controllers.BaseController.java

protected UserDto.OnetimeAuth makeOnetimeAuth(long userId, int validForDays) {
    UserDto.OnetimeAuth rr = new UserDto.OnetimeAuth();
    Calendar now = Calendar.getInstance();
    now.add(Calendar.DATE, validForDays);
    rr.expiresOn = now.getTime();/*from  w  ww . j av  a2  s .  c o m*/
    rr.userId = userId;
    rr.uuid = UUID.randomUUID().toString();
    return rr;
}

From source file:gbc.jtimecalc.AbstractTimeDifferenceCalculatorTest.java

protected static Calendar prepareCalendar(int year, int month, int day, int hour, int minute, int second,
        int millisecond) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.MILLISECOND, millisecond);
    calendar.set(Calendar.SECOND, second);
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.DATE, day);
    calendar.set(Calendar.MONTH, month);
    calendar.set(Calendar.YEAR, year);
    return calendar;
}

From source file:com.cemeterylistingswebtest.test.services.RetrieveAllSubscriberDetailsTest.java

@Test
public void hello() {
    subServ = ctx.getBean(RetrieveAllSubscriberDetails.class);
    repo = ctx.getBean(SubscriberRepository.class);

    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, 2008);
    calendar.set(Calendar.MONTH, Calendar.FEBRUARY);
    calendar.set(Calendar.DATE, 4);

    java.sql.Date javaSqlDate = new java.sql.Date(calendar.getTime().getTime());

    UserRole user = new UserRole.Builder().setLevel(2).build();

    //userRepo.save(user);
    userRoleID = user.getUserRoleID();/*from   ww w .j  ava2  s  .c o  m*/

    Subscriber newSub = new Subscriber.Builder().setEmail("manfredOsulivan@horseRaddish.com")
            .setFirstName("willie").setSurname("Wonker").setPwd("charlie").setUsername("wwonker")
            .setSubscriptionDate(javaSqlDate).setUserRoleID(user).build();

    repo.save(newSub);
    id = newSub.getSubscriberID();

    Subscriber sub = subServ.getSubscriberByUsername("wwonker");
    Assert.assertEquals(sub.getUsername(), "wwonker");

    repo.delete(id);

}

From source file:com.huateng.ebank.framework.util.DateUtil.java

/**
* ?//  w w  w .j  a  v a  2 s .c om
* 
* @param today
* @return
*/
public static Date getLastDateL(Date today) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(today);
    cal.set(Calendar.DATE, 1);// ?1?
    cal.add(Calendar.DATE, -1);// ??
    return cal.getTime();
}

From source file:de.tor.tribes.ui.components.DatePicker.java

/**
 * Creates new form DatePicker// www  .ja  v a2  s .c o  m
 */

public DatePicker() {
    initComponents();
    originalDate = DateUtils.truncate(new Date(), Calendar.DATE);
    selectedDate = originalDate;
    init();
}

From source file:com.cemeterylistingswebtest.test.services.adminRegisterListingServiceTest.java

@Test
public void Test() {

    deadRepo = ctx.getBean(RequiresApprovalDeceasedListingRepository.class);
    adserv = ctx.getBean(AdminRegisterListingService.class);
    subRepo = ctx.getBean(SubscriberRepository.class);
    userRepo = ctx.getBean(UserRoleRepository.class);

    //Initialise date
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, 2008);
    calendar.set(Calendar.MONTH, Calendar.MARCH);
    calendar.set(Calendar.DATE, 5);

    java.sql.Date javaSqlDate = new java.sql.Date(calendar.getTime().getTime());

    //Initialise date
    Calendar calendar2 = Calendar.getInstance();
    calendar2.set(Calendar.YEAR, 2014);
    calendar2.set(Calendar.MONTH, Calendar.JUNE);
    calendar2.set(Calendar.DATE, 20);

    java.sql.Date validDate = new java.sql.Date(calendar2.getTime().getTime());

    //Initialise user role                
    UserRole userRole = new UserRole.Builder().setLevel(2).build();

    Subscriber newSub = new Subscriber.Builder().setEmail("jackieChan@yahoo.com").setFirstName("jackie")
            .setSurname("Chan").setPwd("whaa").setUsername("jChan").setSubscriptionDate(javaSqlDate)
            .setUserRoleID(userRole).setValidUntil(validDate).build();
    subRepo.save(newSub);// ww  w  . jav a2  s .  c  o  m
    subID = newSub.getSubscriberID();

    long listId = adserv.registerDeceasedListingReturn("zaakir", "arendse", "maiden", "male", "date1", "date2",
            "blah", "27", "url", "zaakir27", "0474754", subID);

    Assert.assertFalse(deadRepo.findAll().isEmpty());
    subRepo.delete(newSub);
    deadRepo.delete(listId);

}