Example usage for java.text DateFormat getDateTimeInstance

List of usage examples for java.text DateFormat getDateTimeInstance

Introduction

In this page you can find the example usage for java.text DateFormat getDateTimeInstance.

Prototype

public static final DateFormat getDateTimeInstance(int dateStyle, int timeStyle) 

Source Link

Document

Gets the date/time formatter with the given date and time formatting styles for the default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:org.jboss.tools.openshift.internal.common.ui.utils.DateTimeUtils.java

public static String formatSince(String value, TimeZone timezone) {
    try {//from   ww  w. j a  v  a  2s . co  m
        Date date = parse(value);
        DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.FULL);
        if (timezone != null) {
            formatter.setTimeZone(timezone);
        }
        return formatter.format(date);
    } catch (ParseException e) {
        OpenShiftCommonUIActivator.getDefault().getLogger()
                .logWarning("Unable to parse format duration value: " + value, e);
    }
    return value;
}

From source file:com.m2dl.mini_projet.mini_projet_android.fragment.MarkerDialogFragment.java

public static MarkerDialogFragment newInstance(Photo myPhoto) {
    MarkerDialogFragment dialogMarker = new MarkerDialogFragment();
    Bundle args = new Bundle();
    args.putString(ARG_AUTHOR, myPhoto.getAuthor());
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
    args.putString(ARG_DATE, dateFormat.format(myPhoto.getDate()));
    ArrayList<String> myArrayList = new ArrayList<>();
    for (Tag tag : myPhoto.getTags()) {
        myArrayList.add(tag.getNom());/*from   w  w w.jav a  2  s.c  om*/
    }
    args.putStringArrayList(ARG_TAGS, myArrayList);
    args.putString(ARG_URL, myPhoto.getUrl());
    dialogMarker.setArguments(args);
    return dialogMarker;
}

From source file:org.nuxeo.launcher.info.MessageInfoLogger.java

public void printMessages() {
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    for (MessageInfo message : messages) {
        System.out//  w ww .  j a v a  2 s .  c o  m
                .println("[" + dateFormat.format(message.time) + "] " + message.level + " " + message.message);
    }
}

From source file:Main.java

/**
 * Add a RSS 2.0 Channel Information to a given node - which is your channel node <channel>
 * Note: None of the parameter is supposed to be NULL
 *
 * @param XMLDocument current XML Document
 * @param channelRoot the channel node to which you want the information to be attached to
 * @param title title of your channel/*w ww  .  j  a  v  a 2  s  .com*/
 * @param link  link to your channel home
 * @param description description of your channel
 */
public static void addRSSChannelInformation(Document XMLDocument, Node channelRoot, String title, String link,
        String description) {
    // Title node
    Node entry = XMLDocument.createElement("title");
    entry.appendChild(XMLDocument.createTextNode(title));
    channelRoot.appendChild(entry);

    // Link node
    entry = XMLDocument.createElement("link");
    entry.appendChild(XMLDocument.createTextNode(link));
    channelRoot.appendChild(entry);

    // Description node
    entry = XMLDocument.createElement("description");
    entry.appendChild(XMLDocument.createTextNode(description));
    channelRoot.appendChild(entry);

    // lastBuildDate node
    entry = XMLDocument.createElement("lastBuildDate");
    entry.appendChild(XMLDocument.createTextNode(
            DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(new Date())));
    channelRoot.appendChild(entry);

    // language node
    entry = XMLDocument.createElement("language");
    entry.appendChild(XMLDocument.createTextNode("en-gb"));
    channelRoot.appendChild(entry);
}

From source file:net.opendasharchive.openarchive.db.MediaDeserializer.java

@Override
public Media deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {

    Media mediaResult = new Media();

    JsonObject jobj = (JsonObject) json;

    if (jobj.has("mimeType"))
        mediaResult.setMimeType(jobj.get("mimeType").getAsString());

    if (jobj.has("title"))
        mediaResult.setTitle(jobj.get("title").getAsString());

    if (jobj.has("description"))
        mediaResult.setDescription(jobj.get("description").getAsString());

    if (jobj.has("serverUrl"))
        mediaResult.setServerUrl(jobj.get("serverUrl").getAsString());

    if (jobj.has("location"))
        mediaResult.setLocation(jobj.get("location").getAsString());

    if (jobj.has("tags"))
        mediaResult.setTags(jobj.get("tags").getAsString());

    if (jobj.has("licenseUrl"))
        mediaResult.setLicenseUrl(jobj.get("licenseUrl").getAsString());

    if (jobj.has("author"))
        mediaResult.setAuthor(jobj.get("author").getAsString());

    DateFormat ft = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);

    try {// w  ww  .  ja va2  s .  c o  m
        if (jobj.has("createDate"))
            mediaResult.setCreateDate(ft.parse(jobj.get("createDate").getAsString()));
    } catch (ParseException e) {
        Log.e("MediaDez", "unable to parse date", e);
    }

    try {
        if (jobj.has("updateDate"))
            mediaResult.setUpdateDate(ft.parse(jobj.get("updateDate").getAsString()));
    } catch (ParseException e) {
        Log.e("MediaDez", "unable to parse date", e);
    }

    return mediaResult;
}

From source file:org.kuali.student.ap.coursesearch.util.TimestampPropertyEditor.java

@Override
public String getAsText() {
    Date date = (Date) super.getValue();

    if (null == date) {
        return this.emptyDateText;
    }/* w  w  w  . j  av  a 2  s. c  o  m*/

    if (this.simpleDateFormat.length() == 0) {
        return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(date);
    } else {
        KSDateTimeFormatter format = new KSDateTimeFormatter(simpleDateFormat);
        return format.format(date);
    }
}

From source file:TimeUtil.java

public static String windowFormat(long msecs) {
    Date tDate = new Date(msecs);
    long now = System.currentTimeMillis();
    long diff = now - msecs;
    // start with the last 24 hours
    long comp = MS_PER_DAY;
    // start comparing
    if (diff < comp) {
        // it's within the last 24 hours - just return the time
        DateFormat formatter = DateFormat.getTimeInstance(DateFormat.SHORT);
        return formatter.format(tDate);
    }//  w  ww . j  a v  a  2 s .c  om
    // now expand to another day
    comp += MS_PER_DAY;
    if (diff < comp) {
        // it's within the last 48 hours - just return the time
        DateFormat formatter = DateFormat.getTimeInstance(DateFormat.SHORT);
        return "Yesterday " + formatter.format(tDate);
    }
    // now up it to a week
    comp += 5 * MS_PER_DAY;
    if (diff < comp) {
        // return the day of the week and the time
        // get time to be formatted into a calendar
        GregorianCalendar tCal = new GregorianCalendar();
        tCal.setTime(tDate);
        SimpleDateFormat formatter = new SimpleDateFormat("EEEE");
        return formatter.format(tDate);
    }
    // just return full date
    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    return formatter.format(tDate);
}

From source file:edu.illinois.my.wiki.services.WikiLocationImpl.java

@Override
public String getLastModificationDateString() {
    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT);
    Date modifiedDate = getLastModificationDate();
    return formatter.format(modifiedDate);
}

From source file:com.liferay.social.model.Contact.java

private DateFormat _getDateFormatter() {
    if (_dateFormatter == null) {
        _dateFormatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    }/*from w  w  w  .j  a  va 2s  . c om*/

    return _dateFormatter;
}

From source file:org.kuali.student.myplan.course.util.TimestampPropertyEditor.java

@Override
public String getAsText() {
    Date date = (Date) super.getValue();

    if (null == date) {
        return this.emptyDateText;
    }/*from   w  w w .ja  v a2 s . c  o  m*/

    if (this.simpleDateFormat.length() == 0) {
        return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(date);
    } else if (isPlanAuditSummaryFormat()) {
        SimpleDateFormat monthFormat = new SimpleDateFormat("MMM");
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd");
        SimpleDateFormat timeFormat = new SimpleDateFormat("h:mm aa");
        return wrapInHtml(monthFormat.format(date), dateFormat.format(date), timeFormat.format(date));
    } else {
        SimpleDateFormat format = new SimpleDateFormat(simpleDateFormat);
        return format.format(date);
    }

}