Java Class Libraries - DateFormat
# import java.text.*; import java.util.*; public class DateFormat { public static String getCurrencyFormat(double currency , String format){ String pattern = format; DecimalFormat df = new DecimalFormat(pattern); String s ="$ " + df.format(currency); return s; } public static String getCurrentTime(String format){ SimpleDateFormat sdf = new SimpleDateFormat(format); Date d = new Date(System.currentTimeMillis()); String timeStamp = sdf.format(d); return timeStamp; } public static String getToday(String format){ Calendar calendar = Calendar.getInstance(); SimpleDateFormat dateFormat = new SimpleDateFormat(format); String today =null; try { today = dateFormat.format(calendar.getTime()); } catch (Exception e) { e.printStackTrace(); } return today; } public static String getdate(Timestamp d , String format){ SimpleDateFormat dateFormat = new SimpleDateFormat(format); String day =null; try { day = dateFormat.format(d.getTime()); } catch (Exception e) { e.printStackTrace(); } return day; } public static String stringChecking( String s){ String text = "" ; for (int i = 0; i < s.length(); i++){ if ( s.substring(i,i+1).equals("'") ) text +="\\"+ s.substring(i,i+1); else text += s.substring(i,i+1); } return text; } }
0 意見:
張貼留言