home *** CD-ROM | disk | FTP | other *** search
Java Source | 2003-05-20 | 1.6 KB | 63 lines |
- package nl.pcactive.util;
-
- import java.util.Calendar;
-
- /**
- * <p>Copyright: Copyright (c) 2002</p>
- * <p>Company: Pc-Active</p>
- * @author Benny Lootens
- * @version 2.0
- */
- public final class Settings {
-
- public final static String CHARACTER_ENCODING = "iso-8859-1";
- private static boolean initDone;
-
- public static String getTimeStr(Calendar cal) {
- int d = cal.get(Calendar.DATE);
- int M = cal.get(Calendar.MONTH)+1;
- int y = cal.get(Calendar.YEAR);
- int h = cal.get(Calendar.HOUR) + cal.get(Calendar.AM_PM)*12;
- int m = cal.get(Calendar.MINUTE);
- int s = cal.get(Calendar.SECOND);
- return
- "" + y + "-" + (M<10?"0"+M:""+M) + "-" + (d<10?"0"+d:""+d) + " " + (h<10?"0"+h:""+h)
- + ":" + (m<10?"0"+m:""+m) + ":" + (s<10?"0"+s:""+s);
- }
-
- public static String getTimeStr() {
- return getTimeStr(Calendar.getInstance());
- }
-
- public static String getYear() {
- return "" + Calendar.getInstance().get(Calendar.YEAR);
- }
-
- /** @return a string with replaced parts */
- public static String getReplacedString(String str, String pattern, String replace) {
- String res="";
-
- if (replace==null || replace.length()<1 || pattern==null || pattern.length()<1)
- return str;
-
- try {
- int s = 0;
- int e = 0;
- StringBuffer result = new StringBuffer();
-
- while ((e = str.indexOf(pattern, s)) >= 0) {
- result.append(str.substring(s, e));
- result.append(replace);
- s = e+pattern.length();
- }
- result.append(str.substring(s));
- res = result.toString();
- }
- catch(Throwable e) {
- res = str; // reset the string
- }
- return res;
- }
-
- }
-