List of usage examples for java.text DateFormat format
public final String format(Date date)
From source file:com.sudoku.data.model.User.java
public static com.sudoku.comm.generated.User buildAvroUser(User user) { DateFormat df = new SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH); return com.sudoku.comm.generated.User.newBuilder().setBirthDate(df.format(user.getBirthDate())) .setCreateDate(df.format(user.getCreateDate())).setIpAddress(user.getIpAddress()) .setProfilePicturePath(user.getProfilePicturePath()).setPseudo(user.getPseudo()) .setSalt(user.getSalt()).setUpdateDate(df.format(user.getUpdateDate())).build(); }
From source file:com.gallatinsystems.common.util.S3Util.java
private static String getDate() { final DateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss ", Locale.US); df.setTimeZone(TimeZone.getTimeZone("GMT")); return df.format(new Date()) + "GMT"; }
From source file:Main.java
private static String setDate(int day, Locale locale) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, +day); DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); if (df instanceof SimpleDateFormat) { SimpleDateFormat sdf = (SimpleDateFormat) df; // To show Locale specific short date expression with full year String pattern = sdf.toPattern().replaceAll("y+", "yyyy"); sdf.applyPattern(pattern);//ww w . j ava2s . co m return sdf.format(cal.getTime()); } String formattedDate = df.format(cal.getTime()); return formattedDate; }
From source file:com.swiftcorp.portal.common.util.CalendarUtils.java
public static String getDateStringFromCalendar(Calendar calendar) { DateFormat dateFormat = new SimpleDateFormat(MHEALTH_DATETIME_FORMAT); String dateString = dateFormat.format(calendar.getTime()); // now return the string return dateString; }
From source file:com.fluidops.iwb.api.valueresolver.ValueResolverUtil.java
/** * Converts a system date like '2011-03-31T19:54:33' to user-readable date. * If the input is not a valid system date, the value is returned as is. * /*www . java 2 s .com*/ * @param sysdate * @return */ @SuppressWarnings("deprecation") public static String resolveSystemDate(String sysdate) { Date d = ReadDataManagerImpl.ISOliteralToDate(sysdate); if (d == null) return StringEscapeUtils.escapeHtml(sysdate); DateFormat df = null; if (d.getHours() == 0 && d.getMinutes() == 0 && d.getSeconds() == 0) df = new SimpleDateFormat("MMMMM dd, yyyy"); else df = new SimpleDateFormat("MMMMM dd, yyyy, HH:mm:ss"); return df.format(d); }
From source file:com.zimbra.cs.mailbox.util.MetadataDump.java
static String getTimestampStr(long time) { DateFormat fmt = new SimpleDateFormat("EEE yyyy/MM/dd HH:mm:ss z"); return fmt.format(time); }
From source file:com.alcatel_lucent.nz.wnmsextract.reader.FileSelector.java
public static String calendarToString(Calendar cal) { DateFormat dateFormat = new SimpleDateFormat(FILENAME_DF); return (dateFormat.format(cal.getTime())); }
From source file:org.syncope.core.notification.NotificationTest.java
public static UserTO getSampleTO(final String email) { UserTO userTO = new UserTO(); userTO.setPassword("password123"); userTO.setUsername(email);/*from w w w . ja v a 2 s.c o m*/ AttributeTO fullnameTO = new AttributeTO(); fullnameTO.setSchema("fullname"); fullnameTO.addValue(email); userTO.addAttribute(fullnameTO); AttributeTO firstnameTO = new AttributeTO(); firstnameTO.setSchema("firstname"); firstnameTO.addValue(email); userTO.addAttribute(firstnameTO); AttributeTO surnameTO = new AttributeTO(); surnameTO.setSchema("surname"); surnameTO.addValue("Surname"); userTO.addAttribute(surnameTO); AttributeTO typeTO = new AttributeTO(); typeTO.setSchema("type"); typeTO.addValue("a type"); userTO.addAttribute(typeTO); AttributeTO userIdTO = new AttributeTO(); userIdTO.setSchema("userId"); userIdTO.addValue(email); userTO.addAttribute(userIdTO); AttributeTO emailTO = new AttributeTO(); emailTO.setSchema("email"); emailTO.addValue(email); userTO.addAttribute(emailTO); AttributeTO loginDateTO = new AttributeTO(); loginDateTO.setSchema("loginDate"); DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); loginDateTO.addValue(sdf.format(new Date())); userTO.addAttribute(loginDateTO); // add a derived attribute AttributeTO cnTO = new AttributeTO(); cnTO.setSchema("cn"); userTO.addDerivedAttribute(cnTO); // add a virtual attribute AttributeTO virtualdata = new AttributeTO(); virtualdata.setSchema("virtualdata"); virtualdata.setValues(Collections.singletonList("virtualvalue")); userTO.addVirtualAttribute(virtualdata); return userTO; }
From source file:Main.java
/*** * write a line to the log file//ww w . j a v a2s. c o m * * @param line */ public static void writeToLog(String line) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date(); File f = new File(Environment.getExternalStorageDirectory() + File.separator + folderName); boolean success = true; if (!f.exists()) { success = f.mkdir(); } if (success) { // Do something on success File fileDir = new File(f, dateFormat.format(date) + ".txt"); try { FileOutputStream os = new FileOutputStream(fileDir, true); os.write(line.getBytes()); os.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:edu.temple.cis3238.wiki.utils.StringUtils.java
/** * Formats date string with specified dateformat. * @param dateStr Date to format/* w w w . j ava 2 s . com*/ * @param formattedDateOut Format string * @return Formatted date */ public static String formatDate(String dateStr, String formattedDateOut) { DateFormat dateformat = new SimpleDateFormat(DEFAULT_SQL_DATETIME_FMT, Locale.ENGLISH); DateFormat dateformatOut = new SimpleDateFormat(formattedDateOut, Locale.ENGLISH); try { return dateformatOut.format(dateformat.parse(dateStr)); } catch (Exception ex) { Logger.getLogger(StringUtils.class.getName()).log(Level.SEVERE, null, ex); } return dateStr; }