本文整理汇总了Java中com.ibm.icu.util.TimeZone.getTimeZone方法的典型用法代码示例。如果您正苦于以下问题:Java TimeZone.getTimeZone方法的具体用法?Java TimeZone.getTimeZone怎么用?Java TimeZone.getTimeZone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ibm.icu.util.TimeZone
的用法示例。
在下文中一共展示了TimeZone.getTimeZone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getObjectToFormat
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
/**
* A method to retrieve a formattable object for this object.
* It is important to set the GMT TimeZone to avoid conversions related to TimeZone.
*/
@Override
public Calendar getObjectToFormat() {
if (isNull()) {
return null;
}
// Set GMT TimeZone.
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
// Set to some predefined default. Don't change this default.
cal.set(Calendar.YEAR, 1899);
cal.set(Calendar.MONTH, Calendar.DECEMBER);
cal.set(Calendar.DAY_OF_MONTH, 30);
// Set the TimeOfDay based on this TimeOfDayValue.
cal.set(Calendar.HOUR_OF_DAY, hours);
cal.set(Calendar.MINUTE, minutes);
cal.set(Calendar.SECOND, seconds);
cal.set(Calendar.MILLISECOND, milliseconds);
return cal;
}
示例2: evaluate
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
/**
* Executes this scalar function on the given values. Returns values[0] - values[1] expressed
* as a number value denoting the number of days from one date to the other. Both values can be
* of type date or date-time. Only the date parts of date-time values are used in the calculation.
* Thus the returned number is always an integer.
* The method does not validate the parameters, the user must check the
* parameters before calling this method.
*
* @param values A list of values on which the scalar function will be performed.
*
* @return Value holding the difference, in whole days, between the two given Date/DateTime
* values, or a null value (of type number) if one of the values is null.
*/
public Value evaluate(List<Value> values) {
Value firstValue = values.get(0);
Value secondValue = values.get(1);
// If one of the values is null, return a null number value.
if (firstValue.isNull() || secondValue.isNull()) {
return NumberValue.getNullValue();
}
Date firstDate = getDateFromValue(firstValue);
Date secondDate = getDateFromValue(secondValue);
GregorianCalendar calendar =
new GregorianCalendar(TimeZone.getTimeZone("GMT"));
calendar.setTime(secondDate);
return new NumberValue(calendar.fieldDifference(firstDate, Calendar.DATE));
}
示例3: testTocFind
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
public void testTocFind() throws Exception
{
ITreeNode tree = createTocNormal( );
TOCView view = new TOCView( tree, null, ULocale.ENGLISH, TimeZone
.getTimeZone( "GMT+08:00" ), "html" );
checkTocNode(view, "/", null, 3);
checkTocNode(view, "__TOC_0", "report header", 0);
checkTocNode(view, "__TOC_1", "table", 2);
checkTocNode(view, "__TOC_1_0", "group 1", 2);
checkTocNode(view, "__TOC_1_0_0", "detail 1", 0);
checkTocNode(view, "__TOC_1_0_1", "detail 2", 0);
checkTocNode(view, "__TOC_1_1", "group 2", 2);
checkTocNode(view, "__TOC_1_1_0", "detail 3", 0);
checkTocNode(view, "__TOC_1_1_1", "detail 4", 0);
checkTocNode(view, "__TOC_2_0", "chart 1", 0);
checkTocNode(view, "__TOC_2_1", "chart 2", 0);
assertTrue( view.findTOC( "__TOC_0_0" ) == null );
assertTrue( view.findTOC( "__TOC_1_1_2" ) == null );
assertTrue( view.findTOC( "__TOC_1_1_1_0" ) == null );
assertTrue( view.findTOC( "__TOC_3" ) == null );
}
示例4: afterPropertiesSet
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
boolean timeZoneSet = false;
TimeZone jvmTimeZone = TimeZone.getDefault();
if(jvmTimeZone != null){
String windowsID = TimeZone.getWindowsID(jvmTimeZone.getID());
if(StringUtils.isNotBlank(windowsID)){
log.info("windows time zone context has been set to '"+windowsID+"'. All dates and times sent to (or recieved from) EWS must use this timezone information.");
this.windowsTimeZoneID = windowsID;
timeZoneSet=true;
}else{
log.warn("No windows time zone mapping for "+jvmTimeZone.getID());
}
}else{
log.warn("jvm timezone is not set, this should never happen");
}
if(!timeZoneSet){
log.warn("Failed to identify a matching time zone scheme. Falling back to UTC.");
TimeZone fallbackTimeZone = TimeZone.getTimeZone(FALLBACK_TIMEZONE_ID);
TimeZone.setDefault(fallbackTimeZone);
this.windowsTimeZoneID = FALLBACK_TIMEZONE_ID;
}
}
示例5: getTimeZoneForOffset
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
/**
* Creates an instance of TimeZone for the given offset
* @param offset the offset
* @return A TimeZone with the given offset
*/
private TimeZone getTimeZoneForOffset(int offset) {
if (offset == 0) {
// when offset is 0, we should use "Etc/GMT"
return TimeZone.getTimeZone(TZID_GMT);
}
return ZoneMeta.getCustomTimeZone(offset);
}
示例6: getEquivalentTimeZoneId
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
/**
* Return equivalent Olson timezone id that corresponds to given
* VTIMEZONE definition
* @param vtz VTIMEZONE
* @return equivalent timezone id (null if no equivalent timezone found)
*/
public static String getEquivalentTimeZoneId(VTimeZone vtz) {
com.ibm.icu.util.VTimeZone icuvtz = com.ibm.icu.util.VTimeZone.create(new StringReader(vtz.toString()));
for(String id: allTimezoneIds) {
TimeZone tz = TimeZone.getTimeZone(id);
if(icuvtz.hasSameRules(tz)) {
return id;
}
}
return null;
}
示例7: testTocViewNormal
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
public void testTocViewNormal( ) throws EngineException, IOException
{
ITreeNode tree = createTocNormal( );
System.out.println( toString( tree ) );
TOCView view = new TOCView( tree, null, ULocale.ENGLISH, TimeZone
.getTimeZone( "GMT+08:00" ), "html" );
String output = toString( view.getRoot( ) );
System.out.println( output );
assertEquals( TOC_NORMAL_GOLDEN.replaceAll( "\\s", "" ), output
.replaceAll( "\\s", "" ) );
}
示例8: testTocViewWithFormat
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
public void testTocViewWithFormat( ) throws EngineException, IOException
{
ITreeNode tree = createTocWithFormat( );
System.out.println( toString( tree ) );
TOCView view = new TOCView( tree, null, ULocale.ENGLISH, TimeZone
.getTimeZone( "GMT+08:00" ), "html" );
String output = toString( view.getRoot( ) );
System.out.println( output );
assertEquals( TOC_WITH_FORMAT_GOLDEN.replaceAll( "\\s", "" ), output
.replaceAll( "\\s", "" ) );
}
示例9: testTocViewWithEmptyGorup
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
public void testTocViewWithEmptyGorup( ) throws EngineException,
IOException
{
ITreeNode tree = createTocWithEmptyGroup( );
System.out.println( toString( tree ) );
TOCView view = new TOCView( tree, null, ULocale.ENGLISH, TimeZone
.getTimeZone( "GMT+08:00" ), "html" );
String output = toString( view.getRoot( ) );
System.out.println( output );
assertEquals( TOC_WITH_EMPTY_GROUP_GOLDEN.replaceAll( "\\s", "" ),
output.replaceAll( "\\s", "" ) );
}
示例10: updateTimeForTimeZone
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
/**
* when the TimeZone is changed ,update the time
*
* @param oldID
* @param newID
* @return true
*/
public boolean updateTimeForTimeZone( String oldID, String newID )
{
TimeZone oldZone = TimeZone.getTimeZone( oldID );
TimeZone newZone = TimeZone.getTimeZone( newID );
int oldOff = oldZone.getRawOffset( );
int newOff = newZone.getRawOffset( );
time = time + ( newOff - oldOff );
String text = getShowText( getFormatType( ) );
setText( text );
return true;
}
示例11: updateTimeForTimeZone
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
public boolean updateTimeForTimeZone( String oldID, String newID )
{
long time = cale.getTimeInMillis( );
TimeZone oldZone = TimeZone.getTimeZone( oldID );
TimeZone newZone = TimeZone.getTimeZone( newID );
int oldOff = oldZone.getRawOffset( );
int newOff = newZone.getRawOffset( );
time = time + ( newOff - oldOff );
cale.setTimeInMillis( time );
return true;
}
示例12: testTimeZone
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
@Test
public void testTimeZone()
{
String result = null;
DateFormatter df = null;
Calendar dateCal = Calendar.getInstance( );
dateCal.setTimeZone(java.util.TimeZone.getTimeZone("PST"));
dateCal.set( 1998, 8, 13, 5, 1, 44 );
Date dateTime = dateCal.getTime( );
java.sql.Time sqlTime = new java.sql.Time( dateTime.getTime( ) );
String utcDate = "13 Sep 1998 12:01";
String utcTime = "12:01:44";
TimeZone UTCTimeZone = TimeZone.getTimeZone( "UTC" );
df = new DateFormatter( ULocale.UK, UTCTimeZone );
result = df.format( dateTime );
assertTrue( utcDate.equalsIgnoreCase( result ) );
result = df.format( sqlTime );
assertTrue( utcTime.equalsIgnoreCase( result ) );
String japanDate = "1998/09/13 21:01";
String japanTime = "21:01:44";
TimeZone japanTimeZone = TimeZone.getTimeZone( "Japan" );
df = new DateFormatter( ULocale.JAPAN, japanTimeZone );
result = df.format( dateTime );
assertTrue( japanDate.equalsIgnoreCase( result ) );
result = df.format( sqlTime );
assertTrue( japanTime.equalsIgnoreCase( result ) );
}
示例13: unmappableTimeZoneTest
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
/**
* A timezone with no Windows equivalant is set before initalization.
* This causes {@link RequestServerTimeZoneInterceptor} to set the default {@link TimeZone} to UTC
* AND sets {@link RequestServerTimeZoneInterceptor}.windowsID to UTC
*/
@Test
public void unmappableTimeZoneTest(){
TimeZone badTimeZone = TimeZone.getTimeZone(badTimeZoneID);
TimeZone.setDefault(badTimeZone);
assertEquals(TimeZone.getDefault(), badTimeZone);
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:test-contexts/exchangeContext.xml");
RequestServerTimeZoneInterceptor timeZoneInterceptor = context.getBean(RequestServerTimeZoneInterceptor.class);
assertEquals(RequestServerTimeZoneInterceptor.FALLBACK_TIMEZONE_ID, TimeZone.getDefault().getID());
assertEquals(RequestServerTimeZoneInterceptor.FALLBACK_TIMEZONE_ID, timeZoneInterceptor.getWindowsTimeZoneID());
}
示例14: badTimeZoneContextTest
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
@Test
public void badTimeZoneContextTest() throws DatatypeConfigurationException{
TimeZone badTimeZone = TimeZone.getTimeZone(badTimeZoneID);
TimeZone.setDefault(badTimeZone);
assertEquals(TimeZone.getDefault(), badTimeZone);
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:test-contexts/exchangeContext.xml");
RequestServerTimeZoneInterceptor timeZoneInterceptor = context.getBean(RequestServerTimeZoneInterceptor.class);
assertEquals(RequestServerTimeZoneInterceptor.FALLBACK_TIMEZONE_ID, TimeZone.getDefault().getID());
assertEquals(RequestServerTimeZoneInterceptor.FALLBACK_TIMEZONE_ID, timeZoneInterceptor.getWindowsTimeZoneID());
//time zone currently set to utc, create a date using default time zone
XMLGregorianCalendar now = DateHelp.getXMLGregorianCalendarNow();
//change the default time zone, so the RequestServerTimeZoneInterceptor is out of sync with default time zone.
TimeZone.setDefault(badTimeZone);
ExchangeWebServices ews = context.getBean(ExchangeWebServices.class);
BaseExchangeCalendarDataDao exchangeCalendarDao = context.getBean(BaseExchangeCalendarDataDao.class);
exchangeCalendarDao.setWebServices(ews);
//attempt an ews call, which should fail...
try{
exchangeCalendarDao.getCalendarFolderMap("[email protected]");
fail("exchangeCalendarDao should have thrown exception...");
}catch(ExchangeWebServicesRuntimeException e){}
//change timezone back and call should now succed
TimeZone.setDefault(TimeZone.getTimeZone(RequestServerTimeZoneInterceptor.FALLBACK_TIMEZONE_ID));
exchangeCalendarDao.getCalendarFolderMap(upn);
}
示例15: initCommonOptions
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
/**
* Initializes the common options based on the data extraction option. If
* the passed option doesn't contain common options, use default values.
*
* @param context
* @param options
* options
*/
private void initCommonOptions( IReportContext context,
IDataExtractionOption options )
{
String dateFormat = null;
ICommonDataExtractionOption commonOptions;
if ( options instanceof ICommonDataExtractionOption )
{
commonOptions = (ICommonDataExtractionOption) options;
}
else
{
commonOptions = new CommonDataExtractionOption( options.getOptions( ) );
}
this.isLocaleNeutral = commonOptions.isLocaleNeutralFormat( );
this.localeNeutralFlags = commonOptions.getLocaleNeutralFlags( );
dateFormat = commonOptions.getDateFormat( );
// get locale info
Locale aLocale = null;
if ( commonOptions.getLocale( ) != null )
{
aLocale = commonOptions.getLocale( );
}
else if ( context != null )
{
aLocale = context.getLocale( );
}
if ( aLocale == null )
{
this.locale = ULocale.forLocale( Locale.getDefault( ) );
}
else
{
this.locale = ULocale.forLocale( aLocale );
}
java.util.TimeZone javaTimeZone = commonOptions.getTimeZone( );
if ( javaTimeZone != null )
{
// convert java time zone to ICU time zone
this.timeZone = TimeZone.getTimeZone( javaTimeZone.getID( ) );
}
else if ( context != null )
{
timeZone = context.getTimeZone( );
}
else
{
timeZone = TimeZone.getDefault( );
}
if ( !isLocaleNeutral )
{
dateFormatter = createDateFormatter( dateFormat,
this.locale,
this.timeZone );
}
formatterMap = commonOptions.getFormatter( );
}