本文整理匯總了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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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));
}
}
示例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);
}
}
示例8: getTimeString
import java.text.DateFormat; //導入方法依賴的package包/類
public static String getTimeString(Date d) {
DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT, currentLocale);
return dateFormat.format(d);
}
示例9: getTimeString
import java.text.DateFormat; //導入方法依賴的package包/類
public static String getTimeString(Date d) {
DateFormat dateFormat =
DateFormat.getTimeInstance(DateFormat.SHORT, currentLocale);
return dateFormat.format(d);
}
示例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;
}
示例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"));
}
示例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);
}
示例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 + "";
}