1 25 26 package org.snipsnap.snip; 27 28 import org.snipsnap.app.Application; 29 import org.snipsnap.config.Configuration; 30 import org.radeox.util.i18n.ResourceManager; 31 32 import java.sql.Date ; 33 import java.text.ParseException ; 34 import java.text.SimpleDateFormat ; 35 36 42 43 public class SnipUtil { 44 public static String toName(Date date) { 45 SimpleDateFormat sf = new SimpleDateFormat ("yyyy-MM-dd"); 46 return sf.format(date); 47 } 48 49 public static String toDate(String dateString) { 50 Configuration config = Application.get().getConfiguration(); 51 52 int index = dateString.lastIndexOf('/'); 53 if (index != -1) { 55 dateString = dateString.substring(index+1); 56 } 57 SimpleDateFormat in = new SimpleDateFormat ("yyyy-MM-dd"); 58 SimpleDateFormat out = new SimpleDateFormat (config.getWeblogDateFormat(), 59 ResourceManager.getLocale("i18n.messages")); 60 try { 61 return out.format(in.parse(dateString)); 62 } catch (ParseException e) { 63 return dateString; 64 } 65 } 66 } 67 | Popular Tags |