本文整理汇总了Java中com.ibm.icu.util.TimeZone类的典型用法代码示例。如果您正苦于以下问题:Java TimeZone类的具体用法?Java TimeZone怎么用?Java TimeZone使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TimeZone类属于com.ibm.icu.util包,在下文中一共展示了TimeZone类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setTimeZone
import com.ibm.icu.util.TimeZone; //导入依赖的package包/类
/**
* Set the TimeZone for the calendar used by this DateIntervalFormat object.
* @param zone The new TimeZone, will be cloned for use by this DateIntervalFormat.
* @stable ICU 53
*/
public void setTimeZone(TimeZone zone)
{
// zone is cloned once for all three usages below:
TimeZone zoneToSet = (TimeZone)zone.clone();
if (fDateFormat != null) {
fDateFormat.setTimeZone(zoneToSet);
}
// fDateFormat has the master calendar for the DateIntervalFormat;
// fFromCalendar and fToCalendar are internal work clones of that calendar.
if (fFromCalendar != null) {
fFromCalendar.setTimeZone(zoneToSet);
}
if (fToCalendar != null) {
fToCalendar.setTimeZone(zoneToSet);
}
}
示例2: formatSpecific
import com.ibm.icu.util.TimeZone; //导入依赖的package包/类
/**
* Private method returning the time zone's specific format string.
*
* @param tz the time zone
* @param stdType the name type used for standard time
* @param dstType the name type used for daylight time
* @param date the date
* @param timeType when null, actual time type is set
* @return the time zone's specific format name string
*/
private String formatSpecific(TimeZone tz, NameType stdType, NameType dstType, long date, Output<TimeType> timeType) {
assert(stdType == NameType.LONG_STANDARD || stdType == NameType.SHORT_STANDARD);
assert(dstType == NameType.LONG_DAYLIGHT || dstType == NameType.SHORT_DAYLIGHT);
boolean isDaylight = tz.inDaylightTime(new Date(date));
String name = isDaylight?
getTimeZoneNames().getDisplayName(ZoneMeta.getCanonicalCLDRID(tz), dstType, date) :
getTimeZoneNames().getDisplayName(ZoneMeta.getCanonicalCLDRID(tz), stdType, date);
if (name != null && timeType != null) {
timeType.value = isDaylight ? TimeType.DAYLIGHT : TimeType.STANDARD;
}
return name;
}
示例3: format
import com.ibm.icu.util.TimeZone; //导入依赖的package包/类
/**
* Formats a date or time, which is the standard millis
* since January 1, 1970, 00:00:00 GMT.
* <p>Example: using the US locale:
* "yyyy.MM.dd G 'at' HH:mm:ss zzz" ->> 1996.07.10 AD at 15:08:56 PDT
* @param cal the calendar whose date-time value is to be formatted into a date-time string
* @param toAppendTo where the new date-time text is to be appended
* @param pos the formatting position. On input: an alignment field,
* if desired. On output: the offsets of the alignment field.
* @return the formatted date-time string.
* @see DateFormat
* @stable ICU 2.0
*/
@Override
public StringBuffer format(Calendar cal, StringBuffer toAppendTo,
FieldPosition pos) {
TimeZone backupTZ = null;
if (cal != calendar && !cal.getType().equals(calendar.getType())) {
// Different calendar type
// We use the time and time zone from the input calendar, but
// do not use the input calendar for field calculation.
calendar.setTimeInMillis(cal.getTimeInMillis());
backupTZ = calendar.getTimeZone();
calendar.setTimeZone(cal.getTimeZone());
cal = calendar;
}
StringBuffer result = format(cal, getContext(DisplayContext.Type.CAPITALIZATION), toAppendTo, pos, null);
if (backupTZ != null) {
// Restore the original time zone
calendar.setTimeZone(backupTZ);
}
return result;
}
示例4: createTimeZone
import com.ibm.icu.util.TimeZone; //导入依赖的package包/类
/**
* Creates an instance of JavaTimeZone with the given timezone ID.
* @param id A timezone ID, either a system ID or a custom ID.
* @return An instance of JavaTimeZone for the given ID, or null
* when the ID cannot be understood.
*/
public static JavaTimeZone createTimeZone(String id) {
java.util.TimeZone jtz = null;
if (AVAILABLESET.contains(id)) {
jtz = java.util.TimeZone.getTimeZone(id);
}
if (jtz == null) {
// Use ICU's canonical ID mapping
boolean[] isSystemID = new boolean[1];
String canonicalID = TimeZone.getCanonicalID(id, isSystemID);
if (isSystemID[0] && AVAILABLESET.contains(canonicalID)) {
jtz = java.util.TimeZone.getTimeZone(canonicalID);
}
}
if (jtz == null) {
return null;
}
return new JavaTimeZone(jtz, id);
}
示例5: getSystemZIDs
import com.ibm.icu.util.TimeZone; //导入依赖的package包/类
/**
* Returns an immutable set of system time zone IDs.
* Etc/Unknown is excluded.
* @return An immutable set of system time zone IDs.
*/
private static synchronized Set<String> getSystemZIDs() {
Set<String> systemZones = null;
if (REF_SYSTEM_ZONES != null) {
systemZones = REF_SYSTEM_ZONES.get();
}
if (systemZones == null) {
Set<String> systemIDs = new TreeSet<String>();
String[] allIDs = getZoneIDs();
for (String id : allIDs) {
// exclude Etc/Unknown
if (id.equals(TimeZone.UNKNOWN_ZONE_ID)) {
continue;
}
systemIDs.add(id);
}
systemZones = Collections.unmodifiableSet(systemIDs);
REF_SYSTEM_ZONES = new SoftReference<Set<String>>(systemZones);
}
return systemZones;
}
示例6: getCanonicalSystemZIDs
import com.ibm.icu.util.TimeZone; //导入依赖的package包/类
/**
* Returns an immutable set of canonical system time zone IDs.
* The result set is a subset of {@link #getSystemZIDs()}, but not
* including aliases, such as "US/Eastern".
* @return An immutable set of canonical system time zone IDs.
*/
private static synchronized Set<String> getCanonicalSystemZIDs() {
Set<String> canonicalSystemZones = null;
if (REF_CANONICAL_SYSTEM_ZONES != null) {
canonicalSystemZones = REF_CANONICAL_SYSTEM_ZONES.get();
}
if (canonicalSystemZones == null) {
Set<String> canonicalSystemIDs = new TreeSet<String>();
String[] allIDs = getZoneIDs();
for (String id : allIDs) {
// exclude Etc/Unknown
if (id.equals(TimeZone.UNKNOWN_ZONE_ID)) {
continue;
}
String canonicalID = getCanonicalCLDRID(id);
if (id.equals(canonicalID)) {
canonicalSystemIDs.add(id);
}
}
canonicalSystemZones = Collections.unmodifiableSet(canonicalSystemIDs);
REF_CANONICAL_SYSTEM_ZONES = new SoftReference<Set<String>>(canonicalSystemZones);
}
return canonicalSystemZones;
}
示例7: initialize
import com.ibm.icu.util.TimeZone; //导入依赖的package包/类
/**
* Initialize the transient fields, called from the constructor and
* readObject.
*
* @param locale The locale
*/
private void initialize(ULocale locale) {
ICUResourceBundle bundle = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(
ICUData.ICU_ZONE_BASE_NAME, locale);
_zoneStrings = (ICUResourceBundle)bundle.get(ZONE_STRINGS_BUNDLE);
// TODO: Access is synchronized, can we use a non-concurrent map?
_tzNamesMap = new ConcurrentHashMap<String, ZNames>();
_mzNamesMap = new ConcurrentHashMap<String, ZNames>();
_namesFullyLoaded = false;
_namesTrie = new TextTrieMap<NameInfo>(true);
_namesTrieFullyLoaded = false;
// Preload zone strings for the default time zone
TimeZone tz = TimeZone.getDefault();
String tzCanonicalID = ZoneMeta.getCanonicalCLDRID(tz);
if (tzCanonicalID != null) {
loadStrings(tzCanonicalID);
}
}
示例8: cloneAsThawed
import com.ibm.icu.util.TimeZone; //导入依赖的package包/类
@Override
public TimeZone cloneAsThawed() {
OlsonTimeZone tz = (OlsonTimeZone)super.cloneAsThawed();
if (finalZone != null) {
// TODO Do we really need this?
finalZone.setID(getID());
tz.finalZone = (SimpleTimeZone) finalZone.clone();
}
// Following data are read-only and never changed.
// Therefore, shallow copies should be sufficient.
//
// transitionTimes64
// typeMapData
// typeOffsets
tz.isFrozen = false;
return tz;
}
示例9: init
import com.ibm.icu.util.TimeZone; //导入依赖的package包/类
/**
* Private method initializing the instance of <code>TimeZoneGenericName</code>.
* This method should be called from a constructor and readObject.
*/
private void init() {
if (_tznames == null) {
_tznames = TimeZoneNames.getInstance(_locale);
}
_genericLocationNamesMap = new ConcurrentHashMap<String, String>();
_genericPartialLocationNamesMap = new ConcurrentHashMap<String, String>();
_gnamesTrie = new TextTrieMap<NameInfo>(true);
_gnamesTrieFullyLoaded = false;
// Preload zone strings for the default time zone
TimeZone tz = TimeZone.getDefault();
String tzCanonicalID = ZoneMeta.getCanonicalCLDRID(tz);
if (tzCanonicalID != null) {
loadStrings(tzCanonicalID);
}
}
示例10: getDisplayName
import com.ibm.icu.util.TimeZone; //导入依赖的package包/类
/**
* Returns the display name of the time zone for the given name type
* at the given date, or null if the display name is not available.
*
* @param tz the time zone
* @param type the generic name type - see {@link GenericNameType}
* @param date the date
* @return the display name of the time zone for the given name type
* at the given date, or null.
*/
public String getDisplayName(TimeZone tz, GenericNameType type, long date) {
String name = null;
String tzCanonicalID = null;
switch (type) {
case LOCATION:
tzCanonicalID = ZoneMeta.getCanonicalCLDRID(tz);
if (tzCanonicalID != null) {
name = getGenericLocationName(tzCanonicalID);
}
break;
case LONG:
case SHORT:
name = formatGenericNonLocationName(tz, type, date);
if (name == null) {
tzCanonicalID = ZoneMeta.getCanonicalCLDRID(tz);
if (tzCanonicalID != null) {
name = getGenericLocationName(tzCanonicalID);
}
}
break;
}
return name;
}
示例11: findLocal
import com.ibm.icu.util.TimeZone; //导入依赖的package包/类
/**
* Returns a collection of time zone display name matches for the specified types in the
* given text at the given offset. This method only finds matches from the local trie,
* that contains 1) generic location names and 2) long/short generic partial location names,
* used by this object.
* @param text the text
* @param start the start offset in the text
* @param types the set of name types.
* @return A collection of match info.
*/
private synchronized Collection<GenericMatchInfo> findLocal(String text, int start, EnumSet<GenericNameType> types) {
GenericNameSearchHandler handler = new GenericNameSearchHandler(types);
_gnamesTrie.find(text, start, handler);
if (handler.getMaxMatchLen() == (text.length() - start) || _gnamesTrieFullyLoaded) {
// perfect match
return handler.getMatches();
}
// All names are not yet loaded into the local trie.
// Load all available names into the trie. This could be very heavy.
Set<String> tzIDs = TimeZone.getAvailableIDs(SystemTimeZoneType.CANONICAL, null, null);
for (String tzID : tzIDs) {
loadStrings(tzID);
}
_gnamesTrieFullyLoaded = true;
// now, try it again
handler.resetResults();
_gnamesTrie.find(text, start, handler);
return handler.getMatches();
}
示例12: format
import com.ibm.icu.util.TimeZone; //导入依赖的package包/类
/**
* Format a date/time object.
*
* @param date
* @param timeZone
* @return
* @throws BirtException
*/
public static String format( Date date, TimeZone timeZone ) throws BirtException
{
if ( date == null )
{
return null;
}
Object simpleDateFormatter = DateFormatFactory.getPatternInstance( PatternKey.getPatterKey( "yyyy-MM-dd HH:mm:ss.sZ" ) );
if ( simpleDateFormatter != null )
{
try
{
SimpleDateFormat sdf = ( (SimpleDateFormat) simpleDateFormatter );
sdf.setTimeZone( timeZone );
return sdf.format( date );
}
catch ( Exception e1 )
{
}
}
// for the String can not be parsed, throws a BirtException
throw new CoreException( ResourceConstants.CONVERT_FAILS, new Object[]{
date.toString( ), "ISO8601 Format"
} );
}
示例13: DateTimeValue
import com.ibm.icu.util.TimeZone; //导入依赖的package包/类
/**
* Creates a new DateTime value.
* The input is checked using a gregorian calendar.
* Note this uses the java convention for months:
* January = 0, ..., December = 11.
*
* @param year The year.
* @param month The month.
* @param dayOfMonth The day of month.
* @param hours The hours.
* @param minutes The minutes.
* @param seconds The seconds.
* @param milliseconds The milliseconds.
*
* @throws IllegalArgumentException Thrown if one of the
* parameters is illegal.
*/
public DateTimeValue(int year, int month, int dayOfMonth, int hours,
int minutes, int seconds, int milliseconds) {
// Constructs a GregorianCalendar with the given date and time.
calendar = new GregorianCalendar(year, month, dayOfMonth, hours,
minutes, seconds);
calendar.set(GregorianCalendar.MILLISECOND, milliseconds);
calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
// Check input.
// A RunTimeException is thrown here since it is very unusual for structured
// data to be incorrect.
if ((getYear() != year)
|| (getMonth() != month)
|| (getDayOfMonth() != dayOfMonth)
|| (getHourOfDay() != hours)
|| (getMinute() != minutes)
|| (getSecond() != seconds)
|| (getMillisecond() != milliseconds)) {
throw new IllegalArgumentException("Invalid java date "
+ "(yyyy-MM-dd hh:mm:ss.S): "
+ year + '-' + month + '-' + dayOfMonth + ' ' + hours + ':'
+ minutes + ':' + seconds + '.' + milliseconds);
}
}
示例14: 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));
}
示例15: execute
import com.ibm.icu.util.TimeZone; //导入依赖的package包/类
public Object execute( Object[] arguments, IScriptFunctionContext scriptContext )
throws BirtException
{
if ( scriptContext != null )
{
locale = (ULocale) scriptContext
.findProperty( org.eclipse.birt.core.script.functionservice.IScriptFunctionContext.LOCALE );
timeZone = (TimeZone) scriptContext
.findProperty( org.eclipse.birt.core.script.functionservice.IScriptFunctionContext.TIMEZONE );
}
if ( timeZone == null )
{
timeZone = TimeZone.getDefault( );
}
return executor.execute( arguments, scriptContext );
}