Example usage for java.util Calendar setTimeInMillis

List of usage examples for java.util Calendar setTimeInMillis

Introduction

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

Prototype

public void setTimeInMillis(long millis) 

Source Link

Document

Sets this Calendar's current time from the given long value.

Usage

From source file:com.google.enterprise.connector.db.diffing.JsonObjectUtil.java

/**
 * Adds the last modified date property to the JSON Object.
 *
 * @param propertyName/*  w  w w  .j  a  v  a 2 s .c  o  m*/
 * @param propertyValue
 */
public void setLastModifiedDate(String propertyName, Timestamp propertyValue) {
    if (propertyValue != null) {
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(propertyValue.getTime());
        Value value = Value.getDateValue(cal);
        properties.put(propertyName, ImmutableList.of(value));
        try {
            jsonObject.put(propertyName, value.toString());
        } catch (JSONException e) {
            LOG.warning("Exception for " + propertyName + " with value " + propertyValue + "\n" + e.toString());
        }
    }
}

From source file:de.betterform.xml.xforms.xpath.saxon.function.xpath.FileDate.java

private String formatDateString(long modified, String format) {
    Calendar calendar = new GregorianCalendar(Locale.getDefault());
    calendar.setTimeInMillis(modified);
    SimpleDateFormat simple = null;
    String result;/*w  w  w  . j a  v a2s. c o  m*/
    if (format == null || format.equals("")) {
        //default format
        simple = new SimpleDateFormat("dd.MM.yyyy H:m:s");
    } else {
        //custom format
        try {
            simple = new SimpleDateFormat(format);
        } catch (IllegalArgumentException e) {
            //                result = "Error: illegal Date format string";
            //todo: do something better
        }
    }
    result = simple.format(calendar.getTime());
    return result;
}

From source file:org.openmrs.contrib.metadatarepository.util.DateConverterTest.java

public void testConvertStringToTimestamp() throws Exception {
    final Date today = new Date();
    final Calendar todayCalendar = new GregorianCalendar();
    todayCalendar.setTime(today);//from w ww .  ja  v  a 2  s. co m
    final String datePart = DateUtil.convertDateToString(today);

    final Timestamp time = (Timestamp) converter.convert(Timestamp.class, datePart + " 01:02:03.4");
    final Calendar cal = new GregorianCalendar();
    cal.setTimeInMillis(time.getTime());
    assertEquals(todayCalendar.get(Calendar.YEAR), cal.get(Calendar.YEAR));
    assertEquals(todayCalendar.get(Calendar.MONTH), cal.get(Calendar.MONTH));
    assertEquals(todayCalendar.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.DAY_OF_MONTH));
}

From source file:io.gatling.jenkins.targetenvgraphs.BuildInfoForTargetEnvGraph.java

public Calendar getGraphEndTime() {
    Calendar endTime = (Calendar) this.getBuildStartTime().clone();
    endTime.setTimeInMillis(endTime.getTimeInMillis() + this.getBuildDuration());
    endTime.add(Calendar.MINUTE, BuildInfoForTargetEnvGraph.GRAPH_END_BUFFER_TIME_IN_MINUTES);

    return endTime;
}

From source file:com.android.projecte.townportal.WeatherInfo.java

public String convertDate(long unixTime) {
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm", Locale.US);
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(unixTime * 1000);
    sdf.setTimeZone(cal.getTimeZone());//  w  w  w .j a va  2 s  .c  om
    return sdf.format(cal.getTime());
}

From source file:org.openmrs.web.servlet.ShowGraphServletTest.java

/**
 * @see ShowGraphServlet#getToDate(String)
 *///from   w  ww  . ja  va 2s  .  c o m
@Test
@Verifies(value = "should return date one day after given string date", method = "getToDate(String)")
public void getToDate_shouldReturnDateOneDayAfterGivenStringDate() throws Exception {
    Long time = new Date().getTime() - 100000;
    Calendar timeCal = Calendar.getInstance();
    timeCal.setTimeInMillis(time);
    timeCal.set(timeCal.get(Calendar.YEAR), timeCal.get(Calendar.MONTH), timeCal.get(Calendar.DAY_OF_MONTH) + 1,
            0, 0, 0);

    Date toDate = new ShowGraphServlet().getToDate(Long.toString(time));

    Assert.assertEquals(timeCal.getTimeInMillis(), toDate.getTime());
}

From source file:com.infinities.nova.images.api.DaseinImagesApi.java

private Image toImage(MachineImage machineImage) {
    Image output = new Image();
    Calendar created = Calendar.getInstance();
    created.setTimeInMillis(machineImage.getCreationTimestamp());
    output.setCreated(created);/*  w w w  .j  a  v  a 2 s  . c  o m*/
    output.setId(machineImage.getProviderMachineImageId());
    output.setMetadata(machineImage.getProviderMetadata());
    output.setMinDisk((int) machineImage.getMinimumDiskSizeGb());
    // output.setMinRam();
    output.setName(machineImage.getName());
    // output.setProgress();
    // Image.Server server = new Image.Server();
    // server.setId(input.getServer());
    // output.setServer(server);
    // output.setSize(input.getSize());
    output.setStatus(machineImage.getCurrentState().name());
    // output.setUpdated();
    output.setMetadata(machineImage.getTags());
    return output;
}

From source file:org.scub.foundation.framework.base.messagesource.MessageSourceUtil.java

/**
 * Retourne la conversion de la date en fonction du Locale utilis.
 * @param date la date.//from w w  w.  j  av  a 2s.  c  o  m
 * @return la conversion.
 * @throws ParseException erreur de parsing de la date.
 * @throws java.text.ParseException .
 */
public Calendar getDateParse(final String date) throws ParseException {
    final SimpleDateFormat format = new SimpleDateFormat(messageSourceDetails.loadLocalInfo().getDatePattern());
    final Calendar cal = Calendar.getInstance();
    cal.clear();
    cal.setTimeInMillis(format.parse(date).getTime());
    return cal;
}

From source file:it.generatore.DateRandomGaussianGeneratorTest.java

@Test
public void testGet() throws Exception {
    int i = 0;//from  w w  w  .  j  av  a 2  s . c  o m
    int inFascia = 0;
    int fuoriFascia = 0;
    Calendar cal = GregorianCalendar.getInstance();

    cal.setTimeInMillis(dateRandomGaussianGenerator.minDate);
    cal = DateUtils.truncate(cal, Calendar.DATE);
    System.out.println(sdf.format(cal.getTime()));
    Map<String, Integer> distribuzione = new HashMap<>();
    while (++i <= 24 * 60) {
        cal.add(Calendar.MINUTE, 1);
        distribuzione.put(getHourKey(cal), 0);
    }
    System.out.println(distribuzione.keySet());
    i = 0;
    while (++i <= NUMERO_RECORD) {
        String strDate = dateRandomGaussianGenerator.get();
        //System.out.println("strDate:" + strDate);
        Matcher m = pattern.matcher(strDate);
        assertTrue(m.find());
        strDate = m.group(1);
        //  System.out.println("strDate:" + strDate);
        Date date = sdf.parse(strDate);
        cal.setTime(date);
        String hourKey = getHourKey(cal);
        Integer actualValue = distribuzione.get(hourKey);
        distribuzione.remove(hourKey);
        distribuzione.put(hourKey, actualValue + 1);

        if (cal.get(Calendar.HOUR_OF_DAY) >= 9 && cal.get(Calendar.HOUR_OF_DAY) <= 18) {
            inFascia++;
        } else {
            fuoriFascia++;
        }
        //System.out.println(strDate);
    }
    System.out.println("**** terminato. In fascia: " + inFascia + " fuoriFascia: " + fuoriFascia
            + " % in fascia: " + (inFascia / NUMERO_RECORD));
    assertTrue(inFascia / NUMERO_RECORD >= 0.7d);
    assertTrue(fuoriFascia / NUMERO_RECORD <= 0.3d);
    assertTrue(inFascia + fuoriFascia == NUMERO_RECORD);

}

From source file:com.google.enterprise.connector.db.diffing.DBHandleTest.java

protected void setUp() throws Exception {
    long lastModifiedMillis = new Date().getTime();
    Calendar lastModifiedCalendar = Calendar.getInstance();
    lastModifiedCalendar.setTimeInMillis(lastModifiedMillis);
    lastModified = Value.calendarToIso8601(lastModifiedCalendar);

    properties = ImmutableMap.of(SpiConstants.PROPNAME_DOCID, "1", SpiConstants.PROPNAME_ISPUBLIC, "false",
            SpiConstants.PROPNAME_MIMETYPE, "text/plain", SpiConstants.PROPNAME_LASTMODIFIED, lastModified);

    JsonObjectUtil jsonObjectUtil = new JsonObjectUtil();
    for (Map.Entry<String, String> entry : properties.entrySet()) {
        jsonObjectUtil.setProperty(entry.getKey(), entry.getValue());
    }//  www  .ja v a  2 s .c  o m
    // Overwrites the string in jsonObjectUtil with a date value.
    jsonObjectUtil.setLastModifiedDate(SpiConstants.PROPNAME_LASTMODIFIED, new Timestamp(lastModifiedMillis));
    jsonDocument = new JsonDocument(jsonObjectUtil.getProperties(), jsonObjectUtil.getJsonObject());
}