DateTimeZone.forTimeZone, , Joda , DST - TimeZone.
, "GMT", DST ( DateTimeZone.forID("GMT").isFixed() - true, , , AKA , AKA DST).
, DST ( , DST). DateTimeZone.forID("Europe/London").
DST, , DateTimeZone. DST, 27 /2013 31/Oct/2013, ( , ).
public class CustomTimeZone extends DateTimeZone {
private DateTime dstStart;
private DateTime dstEnd;
protected CustomTimeZone(String id) {
super(id);
this.dstStart = new DateTime(2013, 3, 27, 0, 0, 0, 0, DateTimeZone.UTC);
this.dstEnd = new DateTime(2013, 10, 30, 23, 0, 0, 0, DateTimeZone.UTC);
}
@Override
public String getNameKey(long instant) {
return this.getID();
}
@Override
public int getOffset(long instant) {
if (dstStart.getMillis() <= instant && instant < dstEnd.getMillis()) {
return 3600000;
}
return 0;
}
@Override
public int getStandardOffset(long instant) {
return 0;
}
@Override
public boolean isFixed() {
return false;
}
@Override
public long nextTransition(long instant) {
if (instant < dstStart.getMillis()) {
return dstStart.getMillis();
}
if (instant < dstEnd.getMillis()) {
return dstEnd.getMillis();
}
return instant;
}
@Override
public long previousTransition(long instant) {
if (instant > dstEnd.getMillis()) {
return dstEnd.getMillis();
}
if (instant > dstStart.getMillis()) {
return dstStart.getMillis();
}
return instant;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof CustomTimeZone) {
return getID().equals(((CustomTimeZone) obj).getID());
}
return false;
}
}
:
CustomTimeZone customZone = new CustomTimeZone("Custom");
DateTime d = new DateTime(2013, 4, 20, 0, 0, 0, 0, customZone);
System.out.println(d);
d = new DateTime(2013, 3, 26, 23, 59, 0, 0, customZone);
System.out.println(d);
System.out.println(d.plusMinutes(1));
d = new DateTime(1383173940000L, customZone);
System.out.println(d);
System.out.println(d.plusMinutes(1));
DST, , , DST ( ) .