本文整理汇总了Java中java.util.SimpleTimeZone类的典型用法代码示例。如果您正苦于以下问题:Java SimpleTimeZone类的具体用法?Java SimpleTimeZone怎么用?Java SimpleTimeZone使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleTimeZone类属于java.util包,在下文中一共展示了SimpleTimeZone类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: simpleTimeZoneNoDST
import java.util.SimpleTimeZone; //导入依赖的package包/类
/**
* Checks we correctly build the Timezone for somewhere
* that doesn't have DST (eg Brisbane)
*/
@Test public void simpleTimeZoneNoDST()
{
SimpleTimeZone tz = CalendarTimezoneHelper.buildTimeZone(ICAL_TZ_BRISBANE);
assertNotNull(tz);
assertEquals("Brisbane", tz.getID());
// Doesn't do DST
assertEquals(false, tz.useDaylightTime());
// Always 10 hours ahead
assertEquals(10*60*60*1000, tz.getOffset(date(2011,3,1).getTime()));
assertEquals(10*60*60*1000, tz.getOffset(date(2011,9,1).getTime()));
assertEquals(10*60*60*1000, tz.getOffset(date(2011,11,1).getTime()));
}
示例2: Test4278609
import java.util.SimpleTimeZone; //导入依赖的package包/类
public void Test4278609() {
SimpleTimeZone tz = new SimpleTimeZone(0, "MyTimeZone",
/* DST start day: August, 1, 0:00 */
Calendar.AUGUST, 1, 0, 0,
/* DST end day: January, 1, 0:00 (wall-clock)*/
Calendar.JANUARY, 1, 0, 0,
60 * 60 * 1000);
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
// setting a date using GMT zone just after the end rule of tz zone
cal.clear();
cal.set(Calendar.ERA, GregorianCalendar.AD);
cal.set(1998, Calendar.DECEMBER, 31, 23, 01, 00);
Date date = cal.getTime();
int millis = cal.get(Calendar.HOUR_OF_DAY) * 3600000
+ cal.get(Calendar.MINUTE) * 60000
+ cal.get(Calendar.SECOND) * 1000
+ cal.get(Calendar.MILLISECOND);
/* we must use standard local time */
millis += tz.getRawOffset();
int offset = tz.getOffset(cal.get(Calendar.ERA),
cal.get(Calendar.YEAR),
cal.get(Calendar.MONTH),
cal.get(Calendar.DATE),
cal.get(Calendar.DAY_OF_WEEK),
millis);
if (offset != 0) {
SimpleDateFormat format = new SimpleDateFormat("dd MMM HH:mm:ss zzz",
Locale.US);
format.setTimeZone(tz);
errln("Wrong DST transition: " + tz
+ "\na date just after DST = " + format.format(date)
+ "\ngetOffset = " + offset);
}
}
示例3: Time
import java.util.SimpleTimeZone; //导入依赖的package包/类
/**
* creates a time object from a given date - if the date is between 1950
* and 2049 a UTCTime object is generated, otherwise a GeneralizedTime
* is used.
*/
public Time(
Date date)
{
SimpleTimeZone tz = new SimpleTimeZone(0, "Z");
SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmss");
dateF.setTimeZone(tz);
String d = dateF.format(date) + "Z";
int year = Integer.parseInt(d.substring(0, 4));
if (year < 1950 || year > 2049)
{
time = new DERGeneralizedTime(d);
}
else
{
time = new DERUTCTime(d.substring(2));
}
}
示例4: SegmentedTimeline
import java.util.SimpleTimeZone; //导入依赖的package包/类
/**
* Constructs a new segmented timeline, optionaly using another segmented
* timeline as its base. This chaining of SegmentedTimelines allows further
* segmentation into smaller timelines.
*
* If a base
*
* @param segmentSize the size of a segment in ms. This time unit will be
* used to compute the included and excluded segments of the
* timeline.
* @param segmentsIncluded Number of consecutive segments to include.
* @param segmentsExcluded Number of consecutive segments to exclude.
*/
public SegmentedTimeline(long segmentSize,
int segmentsIncluded,
int segmentsExcluded) {
this.segmentSize = segmentSize;
this.segmentsIncluded = segmentsIncluded;
this.segmentsExcluded = segmentsExcluded;
this.groupSegmentCount = this.segmentsIncluded + this.segmentsExcluded;
this.segmentsIncludedSize = this.segmentsIncluded * this.segmentSize;
this.segmentsExcludedSize = this.segmentsExcluded * this.segmentSize;
this.segmentsGroupSize = this.segmentsIncludedSize
+ this.segmentsExcludedSize;
int offset = TimeZone.getDefault().getRawOffset();
TimeZone z = new SimpleTimeZone(offset, "UTC-" + offset);
this.workingCalendarNoDST = new GregorianCalendar(z,
Locale.getDefault());
}
示例5: firstMondayAfter1900
import java.util.SimpleTimeZone; //导入依赖的package包/类
/**
* Returns the milliseconds for midnight of the first Monday after
* 1-Jan-1900, ignoring daylight savings.
*
* @return The milliseconds.
*
* @since 1.0.7
*/
public static long firstMondayAfter1900() {
int offset = TimeZone.getDefault().getRawOffset();
TimeZone z = new SimpleTimeZone(offset, "UTC-" + offset);
// calculate midnight of first monday after 1/1/1900 relative to
// current locale
Calendar cal = new GregorianCalendar(z);
cal.set(1900, 0, 1, 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
cal.add(Calendar.DATE, 1);
}
//return cal.getTimeInMillis();
// preceding code won't work with JDK 1.3
return cal.getTime().getTime();
}
示例6: generateTimeString
import java.util.SimpleTimeZone; //导入依赖的package包/类
public static String generateTimeString() {
StringBuilder guid = new StringBuilder();
// Create a calendar to get the date formatted properly
String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);
pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
Calendar calendar = new GregorianCalendar(pdt);
Date trialTime = new Date();
calendar.setTime(trialTime);
guid.append(calendar.get(Calendar.YEAR));
guid.append(calendar.get(Calendar.DAY_OF_YEAR));
guid.append(calendar.get(Calendar.HOUR_OF_DAY));
guid.append(calendar.get(Calendar.MINUTE));
guid.append(calendar.get(Calendar.SECOND));
guid.append(calendar.get(Calendar.MILLISECOND));
double random = Math.random();
guid.append(random);
return guid.toString();
}
开发者ID:pengchengluo,项目名称:Peking-University-Open-Research-Data-Platform,代码行数:23,代码来源:DOIDataCiteServiceBean.java
示例7: testEquals
import java.util.SimpleTimeZone; //导入依赖的package包/类
@Test
public void testEquals() {
StorableTimeFence fence1 = StorableTimeFence.inInterval(2, 300);
StorableTimeFence fence2 = StorableTimeFence.inInterval(2, 400);
StorableTimeFence fence3 = StorableTimeFence.inIntervalOfDay(DAY_OF_WEEK_MONDAY, mTimeZone, 20, 300);
StorableTimeFence fence4 = StorableTimeFence.inIntervalOfDay(DAY_OF_WEEK_MONDAY, mTimeZone, 20, 300);
StorableTimeFence fence5 = StorableTimeFence.inIntervalOfDay(DAY_OF_WEEK_MONDAY, new SimpleTimeZone(3, "1"), 20, 400);
StorableTimeFence fence6 = StorableTimeFence.aroundTimeInstant(TimeFence.TIME_INSTANT_SUNRISE, 0, 1);
StorableTimeFence fence7 = StorableTimeFence.aroundTimeInstant(TimeFence.TIME_INSTANT_SUNRISE, 0, 1);
StorableTimeFence fence8 = StorableTimeFence.inTimeInterval(TIME_INTERVAL_AFTERNOON);
StorableTimeFence fence9 = StorableTimeFence.inTimeInterval(TimeFence.TIME_INTERVAL_WEEKDAY);
assertThat(fence1.equals(fence1), is(true));
assertThat(fence3.equals(fence4), is(true));
assertThat(fence2.equals(null), is(false));
assertThat(fence4.equals(fence5), is(false));
assertThat(fence5.equals(fence6), is(false));
assertThat(fence6.equals(fence7), is(true));
assertThat(fence8.equals(fence9), is(false));
}
示例8: Time
import java.util.SimpleTimeZone; //导入依赖的package包/类
/**
* Creates a time object from a given date - if the date is between 1950
* and 2049 a UTCTime object is generated, otherwise a GeneralizedTime
* is used.
*
* @param time a date object representing the time of interest.
*/
public Time(
Date time)
{
SimpleTimeZone tz = new SimpleTimeZone(0, "Z");
SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmss");
dateF.setTimeZone(tz);
String d = dateF.format(time) + "Z";
int year = Integer.parseInt(d.substring(0, 4));
if (year < 1950 || year > 2049)
{
this.time = new DERGeneralizedTime(d);
}
else
{
this.time = new DERUTCTime(d.substring(2));
}
}
示例9: testGetTimeZoneRegion
import java.util.SimpleTimeZone; //导入依赖的package包/类
public void testGetTimeZoneRegion() {
assertEquals("PT", LocaleManager.getTimeZoneRegionAlpha2(
TimeZone.getTimeZone("Europe/Lisbon")));
assertEquals("PT", LocaleManager.getTimeZoneRegionAlpha2(
TimeZone.getTimeZone("Atlantic/Azores")));
assertEquals("PT", LocaleManager.getTimeZoneRegionAlpha2(
TimeZone.getTimeZone("Atlantic/Azores")));
assertEquals("BR", LocaleManager.getTimeZoneRegionAlpha2(
TimeZone.getTimeZone("America/Araguaina")));
assertEquals("US", LocaleManager.getTimeZoneRegionAlpha2(
TimeZone.getTimeZone("America/Adak")));
assertEquals("US", LocaleManager.getTimeZoneRegionAlpha2(
TimeZone.getTimeZone("America/Anchorage")));
assertEquals("US", LocaleManager.getTimeZoneRegionAlpha2(TimeZone.getTimeZone("PST")));
// Test JDK variations
assertEquals("LY", LocaleManager.getTimeZoneRegionAlpha2(
TimeZone.getTimeZone("Africa/Tripoli")));
assertEquals("LY", LocaleManager.getTimeZoneRegionAlpha2(
new SimpleTimeZone(3600000, "Africa/Tripoli")));
assertEquals("LY", LocaleManager.getTimeZoneRegionAlpha2(
new SimpleTimeZone(7200000, "Africa/Tripoli"))); // changed in jdk8
assertNull(LocaleManager.getTimeZoneRegionAlpha2(new SimpleTimeZone(-42, "Africa/Tripoli"))); // wrong
}
示例10: getTimeZone
import java.util.SimpleTimeZone; //导入依赖的package包/类
/**
* Local time zone offset from UTC universal time (zulu) when the VALID
* LOCAL TIME OFFSET flag indicates a valid offset. Otherwise, this method
* returns a static +00:00 indicating no local time offset.
*/
public TimeZone getTimeZone()
{
if( isValidLocalTimeOffset() )
{
int offset = 0;
offset += mMessage.getInt( LOCAL_TIME_OFFSET_HOURS ) * 3600000;
offset += mMessage.get( LOCAL_TIME_OFFSET_HALF_HOUR ) ? 1800000 : 0;
offset = mMessage.get( LOCAL_TIME_OFFSET_SIGN ) ? -offset : offset;
return new SimpleTimeZone( offset, "LOCAL" );
}
else
{
return NO_TIME_ZONE;
}
}
示例11: getCalendar
import java.util.SimpleTimeZone; //导入依赖的package包/类
private Calendar getCalendar(int sign, int hr, int min, int sec) {
int rawOffset = sign * (((hr * 60 + min) * 60 + sec) * 1000);
if (calCache != null && calCacheZone == rawOffset)
return calCache;
StringBuilder zoneID = new StringBuilder("GMT");
zoneID.append(sign < 0 ? '-' : '+');
if (hr < 10) zoneID.append('0');
zoneID.append(hr);
if (min < 10) zoneID.append('0');
zoneID.append(min);
if (sec < 10) zoneID.append('0');
zoneID.append(sec);
TimeZone syntheticTZ = new SimpleTimeZone(rawOffset, zoneID.toString());
calCache = new GregorianCalendar(syntheticTZ);
calCacheZone = rawOffset;
return calCache;
}
示例12: milliSecondsFromNanos
import java.util.SimpleTimeZone; //导入依赖的package包/类
public static Long milliSecondsFromNanos(String timeNanos ) {
if ( timeNanos == null ) return null;
// convert from a nanosecond-extended iso8601-style UTC date yyyy-mm-ddTHH:MM:SS.sssssssss
Calendar c = GregorianCalendar.getInstance(new SimpleTimeZone(0,"UT"));
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
sf.setCalendar(c);
String truncated = timeNanos.substring(0, timeNanos.length()-MILLI_TO_NANO_TIMESTAMP_EXTENSION.length());
Date d;
try {
d = sf.parse(truncated);
} catch (ParseException e) {
e.printStackTrace();
throw new IllegalArgumentException("Unrecognized time format: " + timeNanos);
}
Long v = d.getTime();
return v;
}
示例13: test_ConstructorILjava_lang_StringIIIIIIII
import java.util.SimpleTimeZone; //导入依赖的package包/类
/**
* @tests java.util.SimpleTimeZone#SimpleTimeZone(int, java.lang.String,
* int, int, int, int, int, int, int, int)
*/
public void test_ConstructorILjava_lang_StringIIIIIIII() {
// Test for method java.util.SimpleTimeZone(int, java.lang.String, int,
// int, int, int, int, int, int, int)
SimpleTimeZone st = new SimpleTimeZone(1000, "TEST", Calendar.NOVEMBER,
1, Calendar.SUNDAY, 0, Calendar.NOVEMBER, -1, Calendar.SUNDAY,
0);
assertTrue("Incorrect TZ constructed", st
.inDaylightTime(new GregorianCalendar(1998, Calendar.NOVEMBER,
13).getTime()));
assertTrue("Incorrect TZ constructed", !(st
.inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER,
13).getTime())));
assertEquals("Incorrect TZ constructed", "TEST", st.getID());
assertEquals("Incorrect TZ constructed", 1000, st.getRawOffset());
assertTrue("Incorrect TZ constructed", st.useDaylightTime());
}
示例14: test_ConstructorILjava_lang_StringIIIIIIIII
import java.util.SimpleTimeZone; //导入依赖的package包/类
/**
* @tests java.util.SimpleTimeZone#SimpleTimeZone(int, java.lang.String,
* int, int, int, int, int, int, int, int, int)
*/
public void test_ConstructorILjava_lang_StringIIIIIIIII() {
// Test for method java.util.SimpleTimeZone(int, java.lang.String, int,
// int, int, int, int, int, int, int, int)
SimpleTimeZone st = new SimpleTimeZone(1000, "TEST", Calendar.NOVEMBER,
1, Calendar.SUNDAY, 0, Calendar.NOVEMBER, -1, Calendar.SUNDAY,
0, 1000 * 60 * 60);
assertTrue("Incorrect TZ constructed", st
.inDaylightTime(new GregorianCalendar(1998, Calendar.NOVEMBER,
13).getTime()));
assertTrue("Incorrect TZ constructed", !(st
.inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER,
13).getTime())));
assertEquals("Incorrect TZ constructed", "TEST", st.getID());
assertEquals("Incorrect TZ constructed", 1000, st.getRawOffset());
assertTrue("Incorrect TZ constructed", st.useDaylightTime());
assertTrue("Incorrect TZ constructed",
st.getDSTSavings() == 1000 * 60 * 60);
}
示例15: test_hasSameRulesLjava_util_TimeZone
import java.util.SimpleTimeZone; //导入依赖的package包/类
/**
* @tests java.util.SimpleTimeZone#hasSameRules(java.util.TimeZone)
*/
public void test_hasSameRulesLjava_util_TimeZone() {
// Test for method boolean
// java.util.SimpleTimeZone.hasSameRules(java.util.TimeZone)
SimpleTimeZone st = new SimpleTimeZone(1000, "TEST", Calendar.NOVEMBER,
1, Calendar.SUNDAY, 0, Calendar.NOVEMBER, -1, Calendar.SUNDAY,
0);
SimpleTimeZone sameAsSt = new SimpleTimeZone(1000, "REST",
Calendar.NOVEMBER, 1, Calendar.SUNDAY, 0, Calendar.NOVEMBER,
-1, Calendar.SUNDAY, 0);
SimpleTimeZone notSameAsSt = new SimpleTimeZone(1000, "PEST",
Calendar.NOVEMBER, 2, Calendar.SUNDAY, 0, Calendar.NOVEMBER,
-1, Calendar.SUNDAY, 0);
assertTrue("Time zones have same rules but return false", st
.hasSameRules(sameAsSt));
assertTrue("Time zones have different rules but return true", !st
.hasSameRules(notSameAsSt));
}