List of usage examples for java.text DateFormat format
public final String format(Date date)
From source file:DateUtil.java
/** * Formats given time according to specified locale and time style * * @param time Time to convert/*from www . j ava 2s.c o m*/ * @param locale Locale to use for formatting time * @param timeStyle Time style * @return String representation of time according to given locale and time style * @see java.text.DateFormat */ public static String formatTime(Date time, Locale locale, int timeStyle) { DateFormat formatter = DateFormat.getTimeInstance(timeStyle, locale); return formatter.format(time); }
From source file:com.appunity.ant.Utils.java
protected static File getNewWorkDir(Task task, String workdir, boolean... isClean) throws UnsupportedOperationException { String timedir = task.getProject().getProperty(" work.dir.timestamp"); if (timedir != null && "true".equals(timedir)) { isUserTimeWorkDir = true;//ww w .jav a 2 s. c om } File dir = new File(Utils.obtainValidPath(task, workdir, "work.dir")); if (!dir.exists()) { System.out.println("make dir :" + workdir); dir.mkdirs(); } else { if (!dir.isDirectory()) { File oldfile = new File(workdir + ".bak"); for (int i = 0; oldfile.exists(); i++) { oldfile = new File(workdir + "." + i + ".bak"); } dir.renameTo(oldfile); System.out.println("make dir :" + workdir); dir.mkdirs(); System.out.println( "work dir " + workdir + " is not a dir, will rename old file to " + oldfile.getName()); } } if (!dir.canWrite()) { throw new UnsupportedOperationException("??: " + workdir); } if (isUserTimeWorkDir) { DateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss"); File file = new File(dir, df.format(new Date())); while (file.exists()) { try { Thread.sleep(1000); } catch (InterruptedException ex) { } file = new File(dir, df.format(new Date())); } file.mkdirs(); return file; } else { if (isClean != null && isClean[0]) { for (File object : dir.listFiles()) { if (object.isDirectory()) { try { FileUtils.deleteDirectory(object); System.out.println("delete old dir: " + object); } catch (IOException ex) { Logger.getLogger(InitProjectTask.class.getName()).log(Level.SEVERE, null, ex); } } else { object.delete(); System.out.println("delete old file: " + object); } } } currentWorkDir = dir; return dir; } }
From source file:net.gazeplay.commons.utils.games.Utils.java
/** * @return current date with respect to the format yyyy-MM-dd *///from w w w . jav a 2s. c o m public static String today() { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date(); return dateFormat.format(date); }
From source file:net.gazeplay.commons.utils.games.Utils.java
/** * @return current date with respect to the format dd/MM/yyyy *//* ww w. j av a 2 s.c o m*/ public static String todayCSV() { DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); Date date = new Date(); return dateFormat.format(date); }
From source file:net.gazeplay.commons.utils.games.Utils.java
/** * @return current time with respect to the format yyyy-MM-dd-HH-MM-ss */// w w w .java 2 s .com public static String now() { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); Date date = new Date(); return dateFormat.format(date); }
From source file:Main.java
public static String FormatTime(String Time, String timeformat) { DateFormat formatter; Date convertedDate = null;//from w w w . j ava 2s .co m formatter = new SimpleDateFormat("HH:mm"); try { convertedDate = (Date) formatter.parse(Time); } catch (ParseException e) { //e.printStackTrace(); } if (timeformat.equals("24")) return formatter.format(convertedDate); else return ampmChanger(formatter.format(convertedDate)); }
From source file:DateUtil.java
/** * Formats given date and time according to specified locale and date style * * @param date Date object to convert * @param locale Locale to use for formatting date and time * @param dateStyle Date style/* w w w.java2s. com*/ * @param timeStyle Time style * @return String representation of date and time according to given locale and date style * @see java.text.DateFormat */ public static String formatDateTime(Date date, Locale locale, int dateStyle, int timeStyle) { DateFormat formatter = DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale); return formatter.format(date); }
From source file:com.ecyrd.jspwiki.preferences.Preferences.java
/** * A simple helper function to render a date based on the user preferences. * This is useful for example for all plugins. * /*from w w w . j a v a2 s . c o m*/ * @param context The context which is used to get the preferences * @param date The date to render. * @param tf In which format the date should be rendered. * @return A ready-rendered date. * @since 2.8 */ public static String renderDate(WikiContext context, Date date, TimeFormat tf) { DateFormat df = getDateFormat(context, tf); return df.format(date); }
From source file:gov.nih.nci.caintegrator.common.PermissibleValueUtil.java
private static <T> String toString(T uniqueValue) { final DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); if (uniqueValue instanceof Date) { return dateFormat.format((Date) uniqueValue); } else {/* w ww. j a v a2 s . c o m*/ return uniqueValue.toString(); } }
From source file:com.facebook.infrastructure.utils.FBUtilities.java
public static String getTimestamp() { Date date = new Date(); DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); return df.format(date); }