Created
May 22, 2012 01:19
-
-
Save tocky/2765911 to your computer and use it in GitHub Desktop.
タイムゾーンと日付フォーマットのテスト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.text.SimpleDateFormat; | |
import java.util.Calendar; | |
import java.util.Date; | |
import java.util.Locale; | |
import java.util.TimeZone; | |
import org.apache.commons.lang.time.DateFormatUtils; | |
import org.apache.commons.lang.time.DateUtils; | |
/** | |
* @author 0091007795 | |
* | |
*/ | |
public class TimezoneTest { | |
public static void main(String[] args) throws Exception { | |
System.out.println(TimeZone.getDefault().getDisplayName()); | |
String closingTime = "2012-04-19 12:00:00"; | |
// SimpleDateFormat format = new | |
// SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
// Date d = format.parse(closingTime); | |
final TimeZone tz = TimeZone.getTimeZone("Asia/Tokyo"); | |
final Locale lc = Locale.JAPAN; | |
Calendar cal = Calendar.getInstance(tz, lc); | |
cal.setTimeZone(tz); | |
// cal.setTime(DateUtils.parseDate(closingTime, new | |
// String[]{"yyyy-MM-dd HH:mm:ss"})); | |
// SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
// cal.setTime(format.parse(closingTime)); | |
cal.set(2012, 3, 19, 12, 0, 0); | |
System.out.println(cal.getTime()); | |
System.out.println(cal); | |
System.out.println(DateFormatUtils.format(cal, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), TimeZone.getTimeZone("UTC"), lc)); | |
System.out.println(DateFormatUtils.format(cal, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), TimeZone.getTimeZone("Asia/Tokyo"), lc)); | |
System.out.println(DateFormatUtils.format(cal, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), TimeZone.getTimeZone("Europe/Vienna"), lc)); | |
// long unixTime = d.getTime() / 1000; | |
// System.out.println(unixTime); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment