. withZone (...) :
- , .
, , EST "America/New_York" (, "US/Eastern" ) . (EST) ( DST), DST, . EST , ,
a) ( , EST ),
b) , EST ( ) DST.
/ ( EST America/New_York). , Joda-Time. JSR-310 , , (, java.util.Calendar -).
@Jim Garrison, , , ( ).
( - . ):
, EST, "/_York" . EST- New-York-time ( withZone(EASTERN). , , () ( DateTime, ). :
public static final DateTimeZone EST = DateTimeZone.forID("EST");
public static final DateTimeZone EASTERN = DateTimeZone.forID("US/Eastern");
public static final DateTimeFormatter EST_FORMATTER =
DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSS").withZone(EST);
String input = "2014-03-09 02:00:00.000";
DateTime dt = EST_FORMATTER.parseDateTime(input);
System.out.println(dt);
System.out.println(dt.withZone(EASTERN));
OP:
, EST ( UTC-05, EASTERN ( "America/New_York" EST EDT) , , , . , :
, - , LocalDateTime.
= >
public static final DateTimeZone EST = DateTimeZone.forOffsetHours(-5);
public static final DateTimeZone EDT = DateTimeZone.forOffsetHours(-4);
public static final DateTimeZone EASTERN = DateTimeZone.forID("America/New_York");
public static final org.joda.time.format.DateTimeFormatter FORMATTER =
org.joda.time.format.DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSS");
= >
String input = "2014-03-09 02:00:00.000";
LocalDateTime ldt = FORMATTER.parseLocalDateTime(input);
System.out.println(ldt);
DateTime result;
try {
result = ldt.toDateTime(EASTERN);
} catch (IllegalInstantException ex) {
result = ldt.plusHours(1).toDateTime(EDT);
}
System.out.println(result);
- OP:
toDateTime (DateTimeZone), DateTime, :
, , .
, ().
result = ldt.toDateTime(EASTERN).withEarlierOffsetAtOverlap();
, . : ( )
result = ldt.toDateTime(EDT).withEarlierOffsetAtOverlap();
EDT ( EST ) , . , withEarlierOffsetAtOverlap() . : ldt.plusHours(1) EDT . , , , , ldt.toDateTime(EST) , (EDT!= EST, plusHours(1) ). EDT, , JDK. , (EDT EST), (ldt.plusHours(1).toDateTime(EDT) result = ldt.toDateTime(EST)).