use of java.util.SimpleTimeZone in project OpenAM by OpenRock.
the class AgentBase method getLocalDateAsGMTString.
protected String getLocalDateAsGMTString() {
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z");
dateFormat.setTimeZone(new SimpleTimeZone(0, "GMT"));
Date date = new Date();
return dateFormat.format(date);
}
use of java.util.SimpleTimeZone in project XobotOS by xamarin.
the class SimpleDateFormat method parseTimeZone.
private int parseTimeZone(String string, int offset) {
boolean foundGMT = string.regionMatches(offset, "GMT", 0, 3);
if (foundGMT) {
offset += 3;
}
char sign;
if (offset < string.length() && ((sign = string.charAt(offset)) == '+' || sign == '-')) {
ParsePosition position = new ParsePosition(offset + 1);
Number result = numberFormat.parse(string, position);
if (result == null) {
return -position.getErrorIndex() - 1;
}
int hour = result.intValue();
int raw = hour * 3600000;
int index = position.getIndex();
if (index < string.length() && string.charAt(index) == ':') {
position.setIndex(index + 1);
result = numberFormat.parse(string, position);
if (result == null) {
return -position.getErrorIndex() - 1;
}
int minute = result.intValue();
raw += minute * 60000;
} else if (hour >= 24) {
raw = (hour / 100 * 3600000) + (hour % 100 * 60000);
}
if (sign == '-') {
raw = -raw;
}
calendar.setTimeZone(new SimpleTimeZone(raw, ""));
return position.getIndex();
}
if (foundGMT) {
calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
return offset;
}
String[][] zones = formatData.internalZoneStrings();
for (String[] element : zones) {
for (int j = TimeZones.LONG_NAME; j < TimeZones.NAME_COUNT; j++) {
if (string.regionMatches(true, offset, element[j], 0, element[j].length())) {
TimeZone zone = TimeZone.getTimeZone(element[TimeZones.OLSON_NAME]);
if (zone == null) {
return -offset - 1;
}
int raw = zone.getRawOffset();
if (j == TimeZones.LONG_NAME_DST || j == TimeZones.SHORT_NAME_DST) {
/*
* TODO, http://b/4723412
* We can't use TimeZone#getDSTSavings here because that
* will return 0 if the zone no longer uses DST. We
* should change this to use TimeZone.getOffset(long),
* which requires the complete date to be parsed first.
*/
raw += 3600000;
}
calendar.setTimeZone(new SimpleTimeZone(raw, ""));
return offset + element[j].length();
}
}
}
return -offset - 1;
}
use of java.util.SimpleTimeZone in project jdbc-shards by wplatform.
the class BaseTestCase method assertEquals.
/**
* Check if two values are equal, and if not throw an exception.
*
* @param expected the expected value
* @param actual the actual value
* @throws AssertionError if the values are not equal
*/
public void assertEquals(java.util.Date expected, java.util.Date actual) {
if (expected != actual && !expected.equals(actual)) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
SimpleTimeZone gmt = new SimpleTimeZone(0, "Z");
df.setTimeZone(gmt);
fail("Expected: " + df.format(expected) + " actual: " + df.format(actual));
}
}
use of java.util.SimpleTimeZone in project XobotOS by xamarin.
the class DERUTCTime method getAdjustedDate.
/**
* return the time as an adjusted date
* in the range of 1950 - 2049.
*
* @return a date in the range of 1950 to 2049.
* @exception ParseException if the date string cannot be parsed.
*/
public Date getAdjustedDate() throws ParseException {
SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmssz");
dateF.setTimeZone(new SimpleTimeZone(0, "Z"));
return dateF.parse(getAdjustedTime());
}
use of java.util.SimpleTimeZone in project joda-time by JodaOrg.
the class TestLocalDate_Basics method testToDate_springDST.
public void testToDate_springDST() {
LocalDate base = new LocalDate(2007, 4, 2);
SimpleTimeZone testZone = new SimpleTimeZone(3600000, "NoMidnight", Calendar.APRIL, 2, 0, 0, Calendar.OCTOBER, 2, 0, 3600000);
TimeZone currentZone = TimeZone.getDefault();
try {
TimeZone.setDefault(testZone);
Date test = base.toDate();
check(base, 2007, 4, 2);
assertEquals("Mon Apr 02 01:00:00 GMT+02:00 2007", test.toString());
} finally {
TimeZone.setDefault(currentZone);
}
}
Aggregations