Mercurial > hg > LGServices
diff src/main/java/de/mpiwg/gazetteer/db/DBSectionVersion.java @ 25:86694755415d
new: convert shown edit time to UTC+8
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Fri, 26 Jun 2015 11:32:33 +0200 |
parents | d81a5401b9af |
children | ce2e3f2814c0 |
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/gazetteer/db/DBSectionVersion.java Thu Jun 25 10:53:52 2015 +0200 +++ b/src/main/java/de/mpiwg/gazetteer/db/DBSectionVersion.java Fri Jun 26 11:32:33 2015 +0200 @@ -2,8 +2,16 @@ import java.sql.ResultSet; import java.sql.SQLException; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.TimeZone; + +import org.apache.log4j.Logger; public class DBSectionVersion implements Comparable<DBSectionVersion>{ + private static Logger logger = Logger.getLogger(DBSectionVersion.class); private String id; private String version; @@ -44,7 +52,53 @@ } public String getDate() { - return date; + // TODO time zone convert + // TODO optional time zone + + + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + String dateInString = this.date; + Date dateBerlin = null; + try { + dateBerlin = formatter.parse(dateInString); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + TimeZone tz = TimeZone.getDefault(); + + // From TimeZone Europe/Berlin + /* + System.out.println("\nOrignal TimeZone"); + System.out.println("TimeZone : " + tz.getID() + " - " + tz.getDisplayName()); + System.out.println("TimeZone : " + tz); + System.out.println("Date : " + formatter.format(dateBerlin)); + */ + + // To TimeZone Asia/Taipei + SimpleDateFormat sdfTaipei = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + TimeZone tzInTaipei = TimeZone.getTimeZone("Asia/Taipei"); // Asia/Taipei + sdfTaipei.setTimeZone(tzInTaipei); + + String sDateInTaipei = sdfTaipei.format(dateBerlin); // Convert to String first + Date dateInTaipei = null; + try { + dateInTaipei = formatter.parse(sDateInTaipei); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + /* + System.out.println("New TimeZone"); + System.out.println("TimeZone : " + tzInTaipei.getID() + " - " + tzInTaipei.getDisplayName()); + System.out.println("TimeZone : " + tzInTaipei); + System.out.println("Date (String) : " + dateInTaipei); + System.out.println("Date (Object) : " + formatter.format(dateInTaipei)); + */ + + return formatter.format(dateInTaipei)+"(UTC+8)"; } public void setDate(String date) {