Example usage for java.util GregorianCalendar setTimeInMillis

List of usage examples for java.util GregorianCalendar setTimeInMillis

Introduction

In this page you can find the example usage for java.util GregorianCalendar 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:de.sindzinski.wetter.util.Utility.java

/**
 * Helper method to convert the database representation of the date into something to display
 * to users.  As classy and polished a user experience as "20140102" is, we can do better.
 *
 * @param context      Context to use for resource localization
 * @param timeInMillis The date in milliseconds
 * @return a user-friendly representation of the date.
 *///from ww  w.j a v  a2s.co  m
@SuppressLint("StringFormatMatches")
public static String getDailyDayString(Context context, long timeInMillis, String timeZoneId) {
    // The day string for forecast uses the following logic:
    // For today: "Today, June 8"
    // For tomorrow:  "Tomorrow"
    // For the next 5 days: "Wednesday
    // " (just the day name)
    // For all days after that: "Mon Jun 8"
    //        Log.d("test timezone", timeZoneId);
    TimeZone timeZone;
    if (timeZoneId.equals("")) {
        timeZone = TimeZone.getDefault();
    } else {
        timeZone = TimeZone.getTimeZone(timeZoneId);
    }
    GregorianCalendar gregorianCalendar = new GregorianCalendar(timeZone);
    gregorianCalendar.setTimeInMillis(timeInMillis);
    //        int day = gregorianCalendar.get(GregorianCalendar.DAY_OF_MONTH);

    //code for formatting the date
    Calendar calendar = Calendar.getInstance();
    int today = calendar.get(Calendar.DAY_OF_MONTH);
    calendar.setTimeInMillis(timeInMillis);
    int day = calendar.get(Calendar.DAY_OF_MONTH);

    // If the date we're building the String for is today's date, the format
    // is "Today, June 24"

    if (today == day) {
        int formatId = R.string.format_full_friendly_date;
        SimpleDateFormat shortenedDateFormat = new SimpleDateFormat("dd.MMM");
        shortenedDateFormat.setTimeZone(timeZone);

        return String.format(context.getString(formatId, "Today ",
                gregorianCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault()),
                shortenedDateFormat.format(timeInMillis)));
    } else if (day < today + 7) {
        // If the input date is less than a week in the future, just return the day name.
        String dayName = gregorianCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG,
                Locale.getDefault());//Locale.US);
        return dayName;
    } else {
        try {
            SimpleDateFormat shortDateFormat = new SimpleDateFormat("EEE MMM dd");
            shortDateFormat.setTimeZone(timeZone);
            String dsorig = shortDateFormat.format(timeInMillis);
            Date dconv = shortDateFormat.parse(dsorig);
            String sconv = shortDateFormat.format(dconv);
            return sconv;
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

}

From source file:py.una.pol.karaku.services.util.ServiceUtil.java

/**
 * Converts a {@link Date} into an instance of XMLGregorianCalendar
 * //  w ww . j  a va2 s.co m
 * @param date
 *            Instance of {@link Date} or a null reference
 * @return {@link XMLGregorianCalendar} instance whose value is based upon
 *         the value in the date parameter. If the date parameter is null
 *         then this method will simply return null.
 */
public XMLGregorianCalendar asXMLGregorianCalendar(Date date) {

    if (date == null) {
        return null;
    }
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTimeInMillis(date.getTime());
    return df.newXMLGregorianCalendar(gc);
}

From source file:com.himanshu.um.impl.user.db.dao.UserDaoTest.java

@Test
public void createUser() throws UserCreationException, DatatypeConfigurationException, InterruptedException {
    ApplicationContext context = new ClassPathXmlApplicationContext("um-spring.xml");

    IManager manager = context.getBean(DatabaseManagerImpl.class);
    com.himanshu.um.api.model.User user = new com.himanshu.um.api.model.User();
    user.setUsername("himanshu");
    user.setPassword("password");
    user.setStatus(true);/*w w w.  jav a  2  s . c om*/
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTimeInMillis(new Date().getTime());
    try {
        user.setCreatedDate(DatatypeFactory.newInstance().newXMLGregorianCalendar(cal));
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
        throw e;
    }

    Thread.sleep(3000); //3 seconds sleep to demonstrate last modified date lag

    cal.setTimeInMillis(new Date().getTime());
    try {
        user.setLastModifiedDate(DatatypeFactory.newInstance().newXMLGregorianCalendar(cal));
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
        throw e;
    }

    manager.addNewUser(user);
}

From source file:org.openanzo.rdf.datatype.TypeMaps.java

/**
 * Create an XML Calendar for the time in millis
 * //w w w  . j  a  v a2  s  .c o  m
 * @param millis
 * @return XML Calendar
 */
public static XMLGregorianCalendar getXMLCaledar(long millis) {
    GregorianCalendar cal = new GregorianCalendar(DateUtils.UTC_TIME_ZONE);
    cal.clear();
    cal.setGregorianChange(MIN_DATE);
    cal.setTimeInMillis(millis);
    return TypeMaps.datatypeFactory.newXMLGregorianCalendar(cal);
}

From source file:org.apache.juddi.samples.UddiCustodyTransfer.java

public void TransferBusiness(String fromUser, String fromUserAuthToken, String toUser, String toUserAuthToken,
        String BusinessKey) throws Exception {

    System.out.println("Transfering business key " + BusinessKey);
    DatatypeFactory df = DatatypeFactory.newInstance();
    GregorianCalendar gcal = new GregorianCalendar();
    gcal.setTimeInMillis(System.currentTimeMillis());
    XMLGregorianCalendar xcal = df.newXMLGregorianCalendar(gcal);

    //Create a transfer token from fromUser to toUser
    KeyBag kb = new KeyBag();
    kb.getKey().add(BusinessKey);/*from   w ww. j av  a  2  s.c o  m*/
    Holder<String> nodeidOUT = new Holder<String>();
    Holder<XMLGregorianCalendar> expiresOUT = new Holder<XMLGregorianCalendar>();
    Holder<byte[]> tokenOUT = new Holder<byte[]>();
    custodyTransferPortType.getTransferToken(fromUserAuthToken, kb, nodeidOUT, expiresOUT, tokenOUT);

    System.out.println("Transfer token obtained. Give this to user " + toUser);
    System.out.println("Expires " + expiresOUT.value.toXMLFormat());
    System.out.println("Node " + nodeidOUT.value);
    System.out.println("Token " + org.apache.commons.codec.binary.Base64.encodeBase64String(tokenOUT.value));

    if (toUser == null || toUser.length() == 0 || toUserAuthToken == null || toUserAuthToken.length() == 0) {
        System.out
                .println("The toUser parameters are either null or empty, I can't complete the transfer here");
        return;
    }

    //The magic part happens here, the user ROOT needs to give the user UDDI the token information out of band
    //in practice, all values must match exactly
    //UDDI now accepts the transfer
    TransferEntities te = new TransferEntities();
    te.setAuthInfo(toUserAuthToken);
    te.setKeyBag(kb);
    TransferToken tt = new TransferToken();
    tt.setExpirationTime(expiresOUT.value);
    tt.setNodeID(nodeidOUT.value);
    tt.setOpaqueToken(tokenOUT.value);
    te.setTransferToken(tt);
    System.out.println("Excuting transfer...");
    custodyTransferPortType.transferEntities(te);
    System.out.println("Complete! verifing ownership change...");

    //confirm the transfer
    GetOperationalInfo go = new GetOperationalInfo();
    go.setAuthInfo(fromUserAuthToken);
    go.getEntityKey().add(BusinessKey);
    OperationalInfos operationalInfo = uddiInquiryService.getOperationalInfo(go);
    boolean ok = false;
    boolean found = false;
    for (int i = 0; i < operationalInfo.getOperationalInfo().size(); i++) {
        if (operationalInfo.getOperationalInfo().get(i).getEntityKey().equalsIgnoreCase(BusinessKey)) {
            found = true;
            if (operationalInfo.getOperationalInfo().get(i).getAuthorizedName().equalsIgnoreCase(fromUser)) {
                System.out.println("Transfer unexpected failed");
            }
            if (operationalInfo.getOperationalInfo().get(i).getAuthorizedName().equalsIgnoreCase(toUser)) {
                ok = true;
            }

        }
    }
    if (!found) {
        System.out.println("Could get the operational info the transfed business");
    }
    System.out.println("Transfer " + (ok ? "success" : " failed"));
}

From source file:org.apache.juddi.mapping.MappingModelToApi.java

public static void mapClientSubscriptionInfo(
        org.apache.juddi.model.ClientSubscriptionInfo modelClientSubscriptionInfo,
        org.apache.juddi.api_v3.ClientSubscriptionInfo apiClientSubscriptionInfo)
        throws DispositionReportFaultMessage {

    apiClientSubscriptionInfo.setSubscriptionKey(modelClientSubscriptionInfo.getSubscriptionKey());
    GregorianCalendar gcal = new GregorianCalendar();
    gcal.setTimeInMillis(modelClientSubscriptionInfo.getLastNotified().getTime());
    try {/*from  w ww . j  a  va 2 s  .  co  m*/
        apiClientSubscriptionInfo.setLastModified(DatatypeFactory.newInstance().newXMLGregorianCalendar(gcal));
    } catch (DatatypeConfigurationException ex) {
        logger.warn("unable to create DatatypeFactory", ex);
    }

    if (modelClientSubscriptionInfo.getFromClerk() != null) {
        org.apache.juddi.api_v3.Clerk apiFromClerk = new org.apache.juddi.api_v3.Clerk();
        mapClerk(modelClientSubscriptionInfo.getFromClerk(), apiFromClerk);
        apiClientSubscriptionInfo.setFromClerk(apiFromClerk);
    }
    if (modelClientSubscriptionInfo.getToClerk() != null) {
        org.apache.juddi.api_v3.Clerk apiToClerk = new org.apache.juddi.api_v3.Clerk();
        mapClerk(modelClientSubscriptionInfo.getToClerk(), apiToClerk);
        apiClientSubscriptionInfo.setToClerk(apiToClerk);
    }
}

From source file:org.sakaiproject.nakamura.eventexplorer.ui.EventsWriter.java

/**
 * @param superColumn/*from   w  w  w  .jav  a 2  s. c o  m*/
 * @param writer
 * @throws JSONException
 */
private void writeSuperColumn(SuperColumn superColumn, JSONWriter writer) throws JSONException {
    GregorianCalendar cal = new GregorianCalendar();
    String time = new String(superColumn.getName());
    cal.setTimeInMillis(Long.parseLong(time));

    writer.object();
    writer.key("start").value(format.format(cal));
    Iterator<Column> columns = superColumn.getColumnsIterator();
    String topic = "";
    String path = "";
    while (columns.hasNext()) {
        Column col = columns.next();
        String colName = new String(col.getName());
        if (colName.equals("resourceType")) {
            colName = "title";
        }
        if (colName.equals("path")) {
            path = new String(col.getValue());
        }
        if (colName.equals("event.topics")) {
            topic = new String(col.getValue());
        }
        writer.key(colName);
        writer.value(new String(col.getValue()));
    }
    writer.key("description");
    writer.value(topic + "<br />\n" + path);
    writer.endObject();
}

From source file:org.apache.lens.server.scheduler.SchedulerDAOTest.java

private XJob getTestJob() throws DatatypeConfigurationException {
    XJob job = new XJob();
    job.setTrigger(getTestTrigger());/* w  w  w  .j av a  2s . co  m*/
    job.setName("Test lens Job");
    GregorianCalendar startTime = new GregorianCalendar();
    startTime.setTimeInMillis(System.currentTimeMillis());
    XMLGregorianCalendar start = DatatypeFactory.newInstance().newXMLGregorianCalendar(startTime);

    GregorianCalendar endTime = new GregorianCalendar();
    endTime.setTimeInMillis(System.currentTimeMillis());
    XMLGregorianCalendar end = DatatypeFactory.newInstance().newXMLGregorianCalendar(endTime);

    job.setStartTime(start);
    job.setEndTime(end);
    job.setExecution(getTestExecution());
    return job;
}

From source file:op.tools.SYSCalendar.java

public static GregorianCalendar toGC(Date d) {
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTimeInMillis(d.getTime());
    return gc;/*from  ww w.ja  va 2  s.c o  m*/
}

From source file:op.tools.SYSCalendar.java

public static GregorianCalendar toGC(long l) {
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTimeInMillis(l);
    return gc;/*  w  w  w  .  j  av a  2 s. c  o m*/
}