Example usage for java.text DateFormat format

List of usage examples for java.text DateFormat format

Introduction

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

Prototype

public final String format(Date date) 

Source Link

Document

Formats a Date into a date-time string.

Usage

From source file:Main.java

/**
 * Return a timestamp/*w  w  w. ja  v  a 2  s.c  o m*/
 *
 * @param context Application Context
 */
@SuppressWarnings("UnnecessaryFullyQualifiedName")
public static String getTimestamp(Context context) {
    String timestamp = "unknown";
    Date now = new Date();
    java.text.DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(context);
    java.text.DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(context);
    timestamp = dateFormat.format(now) + ' ' + timeFormat.format(now);
    return timestamp;
}

From source file:Main.java

/**
 * Return a timestamp//  w  ww .  j a  va  2  s. co m
 *
 * @param context Application Context
 */
@SuppressWarnings("UnnecessaryFullyQualifiedName")
public static String getTimestamp(Context context) {
    String timestamp;
    Date now = new Date();
    java.text.DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(context);
    java.text.DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(context);
    timestamp = dateFormat.format(now) + ' ' + timeFormat.format(now);
    return timestamp;
}

From source file:fr.ericlab.util.Util.java

static public String getDate() {
    DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
    Date date = new Date();
    String dateString = dateFormat.format(date).toString();
    return dateString;
}

From source file:com.joyfulmongo.db.javadriver.JFDBUtil.java

public static JSONObject toJSONObject(DBObject o) {
    JSONObject result = new JSONObject();

    try {/*from   w ww.  ja  v a 2 s  . c om*/
        Iterator<String> i = o.keySet().iterator();
        while (i.hasNext()) {
            String k = (String) i.next();
            Object v = o.get(k);
            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.log(Level.FINE, "toJSON Key=[" + k + "]=[" + v + "] " + v.getClass());
            }

            if (v instanceof BasicDBList) {
                result.put(k, toJSONArray((BasicDBList) v));
            } else if (v instanceof DBObject) {
                DBObject dv = (DBObject) v;
                String op = (String) dv.get("__op");
                if (op != null) {
                    Object objs = dv.get("objects");
                    if (objs == null) {
                        // ignore
                    } else if (objs instanceof BasicDBList) {
                        JSONArray jarray = toJSONArray((BasicDBList) objs);
                        result.put(k, jarray);
                    } else {
                        result.put(k, toJSONObject((DBObject) objs));
                    }
                } else {
                    result.put(k, toJSONObject((DBObject) v));
                }
            } else if (v instanceof ObjectId) {
                // ignore the mongo objectId;
            } else if (v instanceof Date) {
                DateFormat format = Utils.getParseDateFormat();
                result.put(k, format.format((Date) v));
            } else {
                result.put(k, v);
            }
        }
        return result;
    } catch (JSONException je) {
        return null;
    }
}

From source file:edu.coeia.charts.LineChartPanel.java

private static String getMonthName(String date) throws ParseException {
    DateFormat fullDate = new SimpleDateFormat("dd/MM/yyyy");
    DateFormat month = new SimpleDateFormat("MMMM");
    Date d = fullDate.parse(date);

    String m = month.format(d);
    return (m);//  www  . jav  a2s  . c  o  m
}

From source file:com.cognifide.actions.msg.replication.ReplicationMessageProducer.java

static String createPath(String relPath, String actionRoot, String randomPath) {
    final String path;
    if (StringUtils.startsWith(relPath, "/")) {
        path = relPath;//from   w ww. j  a  va 2  s .  c o  m
    } else {
        final DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
        path = String.format("%s%s/%s", actionRoot, dateFormat.format(new Date()), relPath);
    }

    if (path.endsWith("/*")) {
        long now = new Date().getTime();
        return String.format("%s%s/%s", StringUtils.removeEnd(path, "*"), generateRandomPathPart(randomPath),
                now);
    } else {
        return path;
    }
}

From source file:Main.java

public static String getDateCurrentTimeZone() {
    StringBuilder sb = new StringBuilder();
    try {/*www . j  av a  2 s .c  o m*/
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT,
                Locale.getDefault());
        Date currentTimeZone = calendar.getTime();
        sb.append(dateFormat.format(currentTimeZone));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return sb.toString();
}

From source file:de.jgoestl.massdatagenerator.MassDataGenerator.java

private static String getFormattedDate(Calendar cal, DateFormat dateFormat) {
    Date time = cal.getTime();//from   www  .  ja  v  a 2  s . c o m
    return dateFormat.format(time);
}

From source file:Main.java

public static String readableDate(String dateString) {
    DateFormat input = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ");
    DateFormat output = new SimpleDateFormat("dd.MM.yyyy HH:mm");

    Date date = new Date();
    try {// ww w .j a v  a2s.c  om
        date = input.parse(dateString);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return output.format(date.getTime());
}

From source file:Main.java

public static boolean validTime(String str, String pattern) {
    DateFormat formatter = new SimpleDateFormat(pattern, Locale.ENGLISH);
    Date date = null;/*from   www.j av a 2s.  c  o  m*/
    try {
        date = (Date) formatter.parse(str);
    } catch (ParseException e) {
        return false;
    }
    return str.equals(formatter.format(date));
}