List of usage examples for java.text SimpleDateFormat applyPattern
public void applyPattern(String pattern)
From source file:jp.co.golorp.emarf.util.DateUtil.java
/** * @return /*www . j av a2 s . c o m*/ */ public static final String getYmd() { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("yyyy/MM/dd"); return sdf.format(getDate()); }
From source file:jp.co.golorp.emarf.util.DateUtil.java
/** * @return /*from ww w . j a va2s. c o m*/ */ public static final String getYmdHmsS() { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("yyyy/MM/dd HH:mm:ss.SSS"); return sdf.format(getDate()); }
From source file:jp.co.golorp.emarf.util.DateUtil.java
/** * @return /*from w w w. j av a 2 s.c om*/ */ public static final String getYmdHms() { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("yyyy/MM/dd HH:mm:ss"); return sdf.format(getDate()); }
From source file:jp.co.golorp.emarf.util.DateUtil.java
/** * @return 4??/*from www .j a v a2s. c o m*/ */ public static final String getYYYY() { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("yyyy"); return sdf.format(getDate()); }
From source file:jp.co.golorp.emarf.util.DateUtil.java
/** * @return 2??/*from w w w .j ava 2 s . c om*/ */ public static final String getMM() { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("MM"); return sdf.format(getDate()); }
From source file:jp.co.golorp.emarf.util.DateUtil.java
/** * @return 2??//from ww w. j a v a2s. c o m */ public static final String getDD() { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("dd"); return sdf.format(getDate()); }
From source file:jp.co.golorp.emarf.util.DateUtil.java
/** * @return 2??/*from w w w . ja v a 2 s . c o m*/ */ public static final String getHH() { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("HH"); return sdf.format(getDate()); }
From source file:jp.co.golorp.emarf.util.DateUtil.java
/** * @return 2??//from www . j a v a 2s. c o m */ public static final String getNN() { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("mm"); return sdf.format(getDate()); }
From source file:Main.java
/** * <p>Parses a string representing a date by trying a variety of different parsers.</p> * /*w w w . j a v a2 s .c o m*/ * <p>The parse will try each parse pattern in turn. * A parse is only deemed sucessful if it parses the whole of the input string. * If no parse patterns match, a ParseException is thrown.</p> * * @param str the date to parse, not null * @param parsePatterns the date format patterns to use, see SimpleDateFormat, not null * @return the parsed date * @throws IllegalArgumentException if the date string or pattern array is null * @throws ParseException if none of the date patterns were suitable */ public static Date parseDate(String str, String[] parsePatterns) throws ParseException { if (str == null || parsePatterns == null) { throw new IllegalArgumentException("Date and Patterns must not be null"); } SimpleDateFormat parser = null; ParsePosition pos = new ParsePosition(0); for (int i = 0; i < parsePatterns.length; i++) { if (i == 0) { parser = new SimpleDateFormat(parsePatterns[0]); } else { parser.applyPattern(parsePatterns[i]); } pos.setIndex(0); Date date = parser.parse(str, pos); if (date != null && pos.getIndex() == str.length()) { return date; } } throw new ParseException("Unable to parse the date: " + str, -1); }
From source file:gr.scify.newsum.Utils.java
/** * // w ww . j av a 2 s.c om * @param lhs First Calendar date * @param rhs Second Calendar date * @return The difference in days between two Calendar dates */ @SuppressLint("SimpleDateFormat") public static int getDiffInDays(Calendar lhs, Calendar rhs) { // Compare using formatted date SimpleDateFormat df = new SimpleDateFormat(); df.applyPattern("yyyy-MM-dd"); String sLhs = df.format(lhs.getTime()); String sRhs = df.format(rhs.getTime()); // debug line // // System.out.println(sLhs + " : " + sRhs + " := " + sLhs.compareTo(sRhs)); // debug line // return sLhs.compareTo(sRhs); }