当前位置: 首页>>代码示例>>Java>>正文


Java DateFormat.getTimeInstance方法代码示例

本文整理汇总了Java中java.text.DateFormat.getTimeInstance方法的典型用法代码示例。如果您正苦于以下问题:Java DateFormat.getTimeInstance方法的具体用法?Java DateFormat.getTimeInstance怎么用?Java DateFormat.getTimeInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.text.DateFormat的用法示例。


在下文中一共展示了DateFormat.getTimeInstance方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test_time_print

import java.text.DateFormat; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Test(dataProvider="time")
public void test_time_print(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
    DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
    Date oldDate = new Date(1970, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
    String text = old.format(oldDate);

    DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale);
    String formatted = f.format(time);
    assertEquals(formatted, text);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:TCKLocalizedPrinterParser.java

示例2: test_time_parse

import java.text.DateFormat; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Test(dataProvider="time")
public void test_time_parse(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
    DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
    Date oldDate = new Date(1970, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
    String text = old.format(oldDate);

    DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale);
    TemporalAccessor parsed = f.parse(text, pos);
    assertEquals(pos.getIndex(), text.length());
    assertEquals(pos.getErrorIndex(), -1);
    assertEquals(LocalTime.from(parsed), time);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:TCKLocalizedPrinterParser.java

示例3: getTime

import java.text.DateFormat; //导入方法依赖的package包/类
/**
 * 获取日期字符串中的时分秒
 * 
 * @param str
 * @param format
 * @return
 */
public static String getTime(String str) {
	try {
		Date date = getDate(str, "yyyy-MM-dd HH:mm:ss");
		DateFormat d3 = DateFormat.getTimeInstance();
		return d3.format(date);
	} catch (Exception ex) {
	}
	return null;
}
 
开发者ID:caichengan,项目名称:ShoppingCartActivity,代码行数:17,代码来源:StringUtil.java

示例4: getTimeInstance

import java.text.DateFormat; //导入方法依赖的package包/类
/**
 * <p>Gets a time formatter instance using the specified style, time
 * zone and locale.</p>
 * 
 * @param style  time style: FULL, LONG, MEDIUM, or SHORT
 * @param timeZone  optional time zone, overrides time zone of
 *  formatted time
 * @param locale  optional locale, overrides system locale
 * @return a localized standard time formatter
 * @throws IllegalArgumentException if the Locale has no time
 *  pattern defined
 */
public static synchronized FastDateFormat getTimeInstance(int style, TimeZone timeZone, Locale locale) {
    Object key = new Integer(style);
    if (timeZone != null) {
        key = new Pair(key, timeZone);
    }
    if (locale != null) {
        key = new Pair(key, locale);
    }

    FastDateFormat format = (FastDateFormat) cTimeInstanceCache.get(key);
    if (format == null) {
        if (locale == null) {
            locale = Locale.getDefault();
        }

        try {
            SimpleDateFormat formatter = (SimpleDateFormat) DateFormat.getTimeInstance(style, locale);
            String pattern = formatter.toPattern();
            format = getInstance(pattern, timeZone, locale);
            cTimeInstanceCache.put(key, format);
        
        } catch (ClassCastException ex) {
            throw new IllegalArgumentException("No date pattern for locale: " + locale);
        }
    }
    return format;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:40,代码来源:FastDateFormat.java

示例5: convertToStringForJSON

import java.text.DateFormat; //导入方法依赖的package包/类
/**
    * Equivalent of <LAMS:Date value="value" type="date|time|both"/>. Use for processing a date to send to the client
    * via JSON. Locale comes from request.getLocale();
    *
    * @param value
    * @param type
    *            TYPE_BOTH (both data and time), TYPE_DATE or TYPE_TIME
    * @param locale
    * @return
    */
   public static String convertToStringForJSON(Date value, Integer style, Integer type, Locale locale) {

HttpSession ss = SessionManager.getSession();
UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
TimeZone tz = user.getTimeZone();

int dateStyle, timeStyle;
switch (style) {
    case DateFormat.SHORT:
	dateStyle = DateFormat.SHORT;
	timeStyle = DateFormat.SHORT;
	break;
    case DateFormat.FULL:
	dateStyle = DateFormat.LONG;
	timeStyle = DateFormat.FULL;
	break;
    default:
	dateStyle = DateFormat.LONG;
	timeStyle = DateFormat.MEDIUM;
}

DateFormat df = null;
switch (type) {
    case TYPE_DATE:
	df = DateFormat.getDateInstance(dateStyle, locale);
	break;
    case TYPE_TIME:
	df = DateFormat.getTimeInstance(timeStyle, locale);
	break;
    default:
	df = DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale);
}

if (tz != null) {
    df.setTimeZone(tz);
}

return df.format(value);
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:50,代码来源:DateUtil.java

示例6: toLocale_helper

import java.text.DateFormat; //导入方法依赖的package包/类
private static String toLocale_helper(double t, int methodId)
{
    DateFormat formatter;
    switch (methodId) {
      case Id_toLocaleString:
        if (localeDateTimeFormatter == null) {
            localeDateTimeFormatter
                = DateFormat.getDateTimeInstance(DateFormat.LONG,
                                                 DateFormat.LONG);
        }
        formatter = localeDateTimeFormatter;
        break;
      case Id_toLocaleTimeString:
        if (localeTimeFormatter == null) {
            localeTimeFormatter
                = DateFormat.getTimeInstance(DateFormat.LONG);
        }
        formatter = localeTimeFormatter;
        break;
      case Id_toLocaleDateString:
        if (localeDateFormatter == null) {
            localeDateFormatter
                = DateFormat.getDateInstance(DateFormat.LONG);
        }
        formatter = localeDateFormatter;
        break;
      default: throw new AssertionError(); // unreachable
    }

    synchronized (formatter) {
        return formatter.format(new Date((long) t));
    }
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:34,代码来源:NativeDate.java

示例7: formatSessionSubtitle

import java.text.DateFormat; //导入方法依赖的package包/类
/**
 * Format and return the given session time and {@link Rooms} values using
 * {@link Config#CONFERENCE_TIMEZONE}.
 */
public static String formatSessionSubtitle(long intervalStart, long intervalEnd, String roomName, StringBuilder recycle,
        Context context, boolean shortFormat) {

    // Determine if the session is in the past
    long currentTimeMillis = UIUtils.getCurrentTime(context);
    boolean conferenceEnded = currentTimeMillis > Config.CONFERENCE_END_MILLIS;
    boolean sessionEnded = currentTimeMillis > intervalEnd;
    if (sessionEnded && !conferenceEnded) {
        return context.getString(R.string.session_finished);
    }

    if (roomName == null) {
        roomName = context.getString(R.string.unknown_room);
    }

    if (shortFormat) {
        TimeZone timeZone = SettingsUtils.getDisplayTimeZone(context);
        Date intervalStartDate = new Date(intervalStart);
        SimpleDateFormat shortDateFormat = new SimpleDateFormat("MMM dd");
        DateFormat shortTimeFormat = DateFormat.getTimeInstance(DateFormat.SHORT);
        shortDateFormat.setTimeZone(timeZone);
        shortTimeFormat.setTimeZone(timeZone);
        return shortDateFormat.format(intervalStartDate) + " "
                + shortTimeFormat.format(intervalStartDate);
    } else {
        String timeInterval = formatIntervalTimeString(intervalStart, intervalEnd, recycle,
                context);
        return context.getString(R.string.session_subtitle, timeInterval, roomName);
    }
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:35,代码来源:UIUtils.java

示例8: getTimeString

import java.text.DateFormat; //导入方法依赖的package包/类
public static String getTimeString(Date d) {
	DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT, currentLocale);
	return dateFormat.format(d);
}
 
开发者ID:ser316asu,项目名称:Neukoelln_SER316,代码行数:5,代码来源:Local.java

示例9: getTimeString

import java.text.DateFormat; //导入方法依赖的package包/类
public static String getTimeString(Date d) {
    DateFormat dateFormat =
        DateFormat.getTimeInstance(DateFormat.SHORT, currentLocale);
    return dateFormat.format(d);
}
 
开发者ID:ser316asu,项目名称:Wilmersdorf_SER316,代码行数:6,代码来源:Local.java

示例10: getDateFormat

import java.text.DateFormat; //导入方法依赖的package包/类
@Override
public DateFormat getDateFormat(TemporalType type, TemporalFormat dateFormat, TemporalFormat timeFormat) {
	TemporalType temporalType = (type != null) ? type : TemporalType.DATE;

	Localization lzn = getLocalization();
	if (lzn == null) {
		throw new LocalizationException("Context is not localized");
	}

	TemporalFormat df = (dateFormat != null) ? dateFormat : TemporalFormat.DEFAULT;
	TemporalFormat tf = (timeFormat != null) ? timeFormat : TemporalFormat.DEFAULT;

	if (df == TemporalFormat.DEFAULT) {
		df = lzn.getDefaultDateTemporalFormat().orElse(getDefaultDateFormatStyle().orElse(TemporalFormat.SHORT));
	}
	if (tf == TemporalFormat.DEFAULT) {
		tf = lzn.getDefaultTimeTemporalFormat().orElse(getDefaultTimeFormatStyle().orElse(TemporalFormat.SHORT));
	}

	DateFormat formatter;

	switch (temporalType) {
	case TIME: {
		if (isUseDateTimeFormatsCache() && timeFormatCache.containsKey(tf)) {
			formatter = timeFormatCache.get(tf);
		} else {
			formatter = DateFormat.getTimeInstance(tf.getTimeStyle(), checkLocalized());
			if (isUseDateTimeFormatsCache()) {
				timeFormatCache.put(tf, formatter);
			}
		}
	}
		break;
	case DATE_TIME: {
		DateTimeFormat dtf = new DateTimeFormat(df, tf);
		if (isUseDateTimeFormatsCache() && dateTimeFormatCache.containsKey(dtf)) {
			formatter = dateTimeFormatCache.get(dtf);
		} else {
			formatter = DateFormat.getDateTimeInstance(df.getDateStyle(), tf.getTimeStyle(), checkLocalized());
			if (isUseDateTimeFormatsCache()) {
				dateTimeFormatCache.put(dtf, formatter);
			}
		}
	}
		break;
	case DATE:
	default: {
		if (isUseDateTimeFormatsCache() && dateFormatCache.containsKey(df)) {
			formatter = dateFormatCache.get(df);
		} else {
			formatter = DateFormat.getDateInstance(df.getDateStyle(), checkLocalized());
			if (isUseDateTimeFormatsCache()) {
				dateFormatCache.put(df, formatter);
			}
		}
	}
		break;
	}

	return formatter;
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:62,代码来源:DefaultLocalizationContext.java

示例11: SublimePickerFragment

import java.text.DateFormat; //导入方法依赖的package包/类
public SublimePickerFragment() {
    // Initialize formatters
    mDateFormatter = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault());
    mTimeFormatter = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault());
    mTimeFormatter.setTimeZone(TimeZone.getTimeZone("GMT+0"));
}
 
开发者ID:jpaijh,项目名称:TYT,代码行数:7,代码来源:SublimePickerFragment.java

示例12: eventCheck

import java.text.DateFormat; //导入方法依赖的package包/类
private String eventCheck(String text)
{
    Pattern pattern = Pattern.compile(EVENT_PATTERN, Pattern.MULTILINE);
    Matcher matcher = pattern.matcher(text);

    DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT);

    // Find matches
    while (matcher.find())
    {
        // Parse time
        Date date = null;
        try
        {
            date = dateFormat.parse(matcher.group(1));
        }

        // Ignore errors
        catch (Exception e)
        {
            continue;
        }

        Calendar time = Calendar.getInstance();
        time.setTime(date);

        Calendar startTime =
            new GregorianCalendar(currEntry.get(Calendar.YEAR),
                                  currEntry.get(Calendar.MONTH),
                                  currEntry.get(Calendar.DATE),
                                  time.get(Calendar.HOUR_OF_DAY),
                                  time.get(Calendar.MINUTE));
        Calendar endTime =
            new GregorianCalendar(currEntry.get(Calendar.YEAR),
                                  currEntry.get(Calendar.MONTH),
                                  currEntry.get(Calendar.DATE),
                                  time.get(Calendar.HOUR_OF_DAY),
                                  time.get(Calendar.MINUTE));
        // Add an hour
        endTime.add(Calendar.HOUR, 1);

        String title = matcher.group(2);

        QueryHandler.insertEvent(this, startTime.getTimeInMillis(),
                                 endTime.getTimeInMillis(), title);
    }

    return matcher.replaceAll(EVENT_TEMPLATE);
}
 
开发者ID:billthefarmer,项目名称:diary,代码行数:50,代码来源:Diary.java

示例13: getTime

import java.text.DateFormat; //导入方法依赖的package包/类
public String getTime(Calendar cal) {
    DateFormat finalTimeFormat;

    finalTimeFormat = DateFormat.getTimeInstance(DateFormat.SHORT);


    String finalTime = finalTimeFormat.format(cal.getTime());
    return finalTime + "";
}
 
开发者ID:adithya321,项目名称:SOS-The-Healthcare-Companion,代码行数:10,代码来源:FormatDateTime.java


注:本文中的java.text.DateFormat.getTimeInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。