List of usage examples for java.text DateFormat format
public final String format(Date date)
From source file:Debug.java
public static String getDebug(String message, Calendar value) { DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); return getDebug(message, (value == null) ? "null" : df.format(value.getTime())); }
From source file:org.pentaho.di.core.util.StringUtil.java
/** * Giving back a date/time string in the format following the rule from the most to the least significant * * @param date// w ww . j a v a 2 s . c o m * the date to convert * @param milliseconds * true when milliseconds should be added * @return a string in the form yyyddMM_hhmmssSSS (milliseconds will be optional) */ public static String getFormattedDateTime(Date date, boolean milliseconds) { DateFormat dateFormat = null; if (milliseconds) { dateFormat = new SimpleDateFormat(Const.GENERALIZED_DATE_TIME_FORMAT_MILLIS); } else { dateFormat = new SimpleDateFormat(Const.GENERALIZED_DATE_TIME_FORMAT); } return dateFormat.format(date); }
From source file:com.alkacon.opencms.documentcenter.NewDocumentsTree.java
/** * Creates a nice localized date String from the given String.<p> * //from w w w .j a v a2 s . c o m * @param dateLongString the date as String representation of a long value * @param localeString the current locale String * @return nice formatted date string in long mode (e.g. 15. April 2003) */ public static String getNiceDate(String dateLongString, String localeString) { Locale locale = new Locale(localeString.toLowerCase()); DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, locale); Calendar cal = new GregorianCalendar(locale); try { cal.setTimeInMillis(Long.parseLong(dateLongString)); } catch (Exception e) { //noop } return df.format(cal.getTime()); }
From source file:com.alkacon.opencms.documentcenter.NewDocumentsTree.java
/** * Creates a nice localized date String from the given day, month and year Strings.<p> * /* ww w . j av a 2 s . co m*/ * @param day the number of the day as String * @param month the number of the month as String * @param year the number of the year as String * @param localeString the current locale String * @return nice formatted date string in long mode (e.g. 15. April 2003) */ public static String getNiceDate(String day, String month, String year, String localeString) { Locale locale = new Locale(localeString.toLowerCase()); DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, locale); Calendar cal = new GregorianCalendar(locale); try { cal.set(Integer.parseInt(year), Integer.parseInt(month) - 1, Integer.parseInt(day)); } catch (Exception e) { // noop } return df.format(cal.getTime()); }
From source file:com.webbfontaine.valuewebb.model.util.Utils.java
public static String dateToLocaleString(Date date) { String toStringDate;/*from www . j av a 2 s. c om*/ if (date == null) { toStringDate = ""; } else { DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, LocaleSelector.instance().getLocale()); toStringDate = dateFormat.format(date); } return toStringDate; }
From source file:com.opendesign.utils.Day.java
public static String toString(Date date, String format) { DateFormat output = new SimpleDateFormat(format); return output.format(date); }
From source file:com.rsltc.profiledata.main.MainActivity.java
public static DataReadRequest queryFitnessData() { Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); Date now = new Date(); cal.setTime(now);//from w ww .j a va2 s . c o m // cal.add(Calendar.YEAR, -1); // cal.set(2015,7,20); long endTime = cal.getTimeInMillis(); cal.add(Calendar.YEAR, -1); long startTime = cal.getTimeInMillis(); java.text.DateFormat dateFormat = getDateInstance(); Log.i(TAG, "Range Start: " + dateFormat.format(startTime)); Log.i(TAG, "Range End: " + dateFormat.format(endTime)); DataReadRequest readRequest = new DataReadRequest.Builder() .aggregate(DataType.TYPE_DISTANCE_DELTA, DataType.AGGREGATE_DISTANCE_DELTA) // .read(DataType.TYPE_WEIGHT) // .read(DataType.TYPE_HEIGHT) // .read(DataType.TYPE_HEART_RATE_BPM) .bucketByActivitySegment(5, TimeUnit.MINUTES) // .bucketByActivityType(1, TimeUnit.SECONDS) // .bucketByTime(1, TimeUnit.DAYS) .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS).build(); return readRequest; }
From source file:dao.DashboardDAO.java
private static List<DashboardBarData> getDashboardBarData(String userId, String query) { Map<String, Object> result = null; if (StringUtils.isNotBlank(userId)) { List<LdapInfo> ldapInfoList = JiraDAO.getCurrentUserLdapInfo(userId); if (ldapInfoList != null && ldapInfoList.size() > 0 && ldapInfoList.get(0) != null) { String orgHierarchy = ldapInfoList.get(0).orgHierarchy; if (StringUtils.isNotBlank(orgHierarchy)) { result = getJdbcTemplate().queryForMap(query, orgHierarchy, orgHierarchy + "/%"); }//from w w w .ja va 2s .co m } } List<DashboardBarData> barDataList = new ArrayList<>(); if (result != null && result.size() >= 6) { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); DateFormat df = new SimpleDateFormat("MM/yy"); for (int i = 1; i <= 6; i++) { BigDecimal value = (BigDecimal) result.get(i + "_month_ago"); DashboardBarData dashboardBarData = new DashboardBarData(); dashboardBarData.label = df.format(cal.getTime()); if (value != null) { dashboardBarData.value = value.longValue(); } else { dashboardBarData.value = 0L; } barDataList.add(dashboardBarData); cal.add(Calendar.MONTH, -1); } } return barDataList; }
From source file:com.hcc.cms.util.PageUtils.java
public static String getFormattedDate(String dateReceivedFromUser) { DateFormat userDateFormat = new SimpleDateFormat("MM/dd/yy"); DateFormat dateFormatNeeded = new SimpleDateFormat("MMMM dd, yyyy"); Date date;/* ww w . ja va 2 s. c o m*/ try { date = userDateFormat.parse(dateReceivedFromUser); String convertedDate = dateFormatNeeded.format(date); return convertedDate; } catch (ParseException e) { log.error("Error while parsing date", e); } return dateReceivedFromUser; }
From source file:cn.ipanel.apps.portalBackOffice.util.CommonsFiend.java
/** * //from w ww . j a va2s . c om * * @param date * yyyy-MM * @return * @author lixiang * @throws ParseException * @create 2008-9-22 01:59:33 * @since */ public static List getDatesList(String date) throws ParseException { DateFormat format = new SimpleDateFormat("yyyy-MM"); Calendar time = Calendar.getInstance(); time.clear(); Date d1 = format.parse(date); time.setTime(d1); int day = time.getActualMaximum(Calendar.DAY_OF_MONTH); DateFormat formats = new SimpleDateFormat(Defines.FORMAT_DATE_STRING); List list = new ArrayList(); for (int i = 1; i <= day; i++) { String s = format.format(d1) + "-" + i; Date sss = formats.parse(s); String dd = formats.format(sss); list.add(dd); } return list; }