本文整理汇总了Java中java.text.DateFormat.format方法的典型用法代码示例。如果您正苦于以下问题:Java DateFormat.format方法的具体用法?Java DateFormat.format怎么用?Java DateFormat.format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.DateFormat
的用法示例。
在下文中一共展示了DateFormat.format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPreviousYearEnd
import java.text.DateFormat; //导入方法依赖的package包/类
public static String getPreviousYearEnd() {
weeks--;
int yearPlus = getYearPlus();
GregorianCalendar currentDate = new GregorianCalendar();
currentDate.add(GregorianCalendar.DATE, yearPlus + MaxYear * weeks
+ (MaxYear - 1));
Date yearDay = currentDate.getTime();
DateFormat df = DateFormat.getDateInstance();
String preYearDay = df.format(yearDay);
getThisSeasonTime(11);
return preYearDay;
}
示例2: formatDate
import java.text.DateFormat; //导入方法依赖的package包/类
/**
* Format the given date on the given format
* @param date : the date to format.
* @param format : the format to correct by.
* @return a string representation of the formatted date.
*/
public static String formatDate(Date date, String format)
{
if (date == null)
{
return null;
}
final DateFormat dateFormat = new SimpleDateFormat(format);
return dateFormat.format(date);
}
示例3: estimateMaximumTickLabelHeight
import java.text.DateFormat; //导入方法依赖的package包/类
/**
* Estimates the maximum width of the tick labels, assuming the specified tick unit is used.
* <P>
* Rather than computing the string bounds of every tick on the axis, we just look at two
* values: the lower bound and the upper bound for the axis. These two values will usually
* be representative.
*
* @param g2 the graphics device.
* @param unit the tick unit to use for calculation.
*
* @return the estimated maximum width of the tick labels.
*/
private double estimateMaximumTickLabelHeight(Graphics2D g2, DateTickUnit unit) {
Insets tickLabelInsets = getTickLabelInsets();
double result = tickLabelInsets.top + tickLabelInsets.bottom;
Font tickLabelFont = getTickLabelFont();
FontRenderContext frc = g2.getFontRenderContext();
LineMetrics lm = tickLabelFont.getLineMetrics("ABCxyz", frc);
if (!isVerticalTickLabels()) {
// all tick labels have the same width (equal to the height of the font)...
result += lm.getHeight();
}
else {
// look at lower and upper bounds...
DateRange range = (DateRange) getRange();
Date lower = range.getLowerDate();
Date upper = range.getUpperDate();
String lowerStr = null;
String upperStr = null;
DateFormat formatter = getDateFormatOverride();
if (formatter != null) {
lowerStr = formatter.format(lower);
upperStr = formatter.format(upper);
}
else {
lowerStr = unit.dateToString(lower);
upperStr = unit.dateToString(upper);
}
FontMetrics fm = g2.getFontMetrics(tickLabelFont);
double w1 = fm.stringWidth(lowerStr);
double w2 = fm.stringWidth(upperStr);
result += Math.max(w1, w2);
}
return result;
}
示例4: formatPlayTime
import java.text.DateFormat; //导入方法依赖的package包/类
/**
* 格式化时间
*
* @param time
* @return
*/
@SuppressLint("SimpleDateFormat")
public static String formatPlayTime(long time) {
if(time<=0)
return "00:00";
DateFormat formatter = new SimpleDateFormat("mm:ss");
return formatter.format(new Date(time));
}
示例5: test_date_print
import java.text.DateFormat; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Test(dataProvider="date")
public void test_date_print(LocalDate date, FormatStyle dateStyle, int dateStyleOld, Locale locale) {
DateFormat old = DateFormat.getDateInstance(dateStyleOld, locale);
Date oldDate = new Date(date.getYear() - 1900, date.getMonthValue() - 1, date.getDayOfMonth());
String text = old.format(oldDate);
DateTimeFormatter f = builder.appendLocalized(dateStyle, null).toFormatter(locale);
String formatted = f.format(date);
assertEquals(formatted, text);
}
示例6: getDisplayCreationTimeForSession
import java.text.DateFormat; //导入方法依赖的package包/类
public static String getDisplayCreationTimeForSession(Session in_session) {
try {
DateFormat formatter = new SimpleDateFormat(DATE_TIME_FORMAT);
return formatter.format(new Date(in_session.getCreationTime()));
} catch (IllegalStateException ise) {
//ignore: invalidated session
return "";
}
}
示例7: createItemArray
import java.text.DateFormat; //导入方法依赖的package包/类
/**
* Creates the array of items that can be passed to the
* {@link MessageFormat} class for creating labels.
*
* @param dataset the dataset (<code>null</code> not permitted).
* @param series the series (zero-based index).
* @param item the item (zero-based index).
*
* @return The items (never <code>null</code>).
*/
protected Object[] createItemArray(XYZDataset dataset,
int series, int item) {
Object[] result = new Object[4];
result[0] = dataset.getSeriesKey(series).toString();
Number x = dataset.getX(series, item);
DateFormat xf = getXDateFormat();
if (xf != null) {
result[1] = xf.format(x);
}
else {
result[1] = getXFormat().format(x);
}
Number y = dataset.getY(series, item);
DateFormat yf = getYDateFormat();
if (yf != null) {
result[2] = yf.format(y);
}
else {
result[2] = getYFormat().format(y);
}
Number z = dataset.getZ(series, item);
if (this.zDateFormat != null) {
result[3] = this.zDateFormat.format(z);
}
else {
result[3] = this.zFormat.format(z);
}
return result;
}
示例8: getDateString
import java.text.DateFormat; //导入方法依赖的package包/类
/**
* Get the {@code Date} the score was achieved as a formatted string.
*
* @return The date string.
*/
public final String getDateString() {
DateFormat format = DateFormat
.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
return format.format(date);
}
示例9: getDateString
import java.text.DateFormat; //导入方法依赖的package包/类
public static String getDateString(java.sql.Date date, String pattern) {
DateFormat fmt = new SimpleDateFormat(pattern);
return fmt.format(date);
}
示例10: getTime
import java.text.DateFormat; //导入方法依赖的package包/类
public String getTime() {
Date date = new Date();
date.getTime();
DateFormat formatter = new SimpleDateFormat(pattern);
return formatter.format(date);
}
示例11: getMonth
import java.text.DateFormat; //导入方法依赖的package包/类
public String getMonth() {
DateFormat finalFormat = new SimpleDateFormat("MM");
return finalFormat.format(origDateTime);
}
示例12: dateTimeFormat
import java.text.DateFormat; //导入方法依赖的package包/类
/**
* Formats a given date+time value to an ISO 8601 string.
* @param dateTime value to format, as a Date
*/
public static String dateTimeFormat(Date dateTime) {
DateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
iso8601.setTimeZone(UTC);
return iso8601.format(dateTime);
}
示例13: getTime
import java.text.DateFormat; //导入方法依赖的package包/类
private static String getTime() {
Date date = new Date();
date.getTime();
DateFormat formatter = new SimpleDateFormat("HH.mm.ss");
return formatter.format(date);
}
示例14: getTimeString
import java.text.DateFormat; //导入方法依赖的package包/类
public static String getTimeString(Date d) {
DateFormat dateFormat =
DateFormat.getTimeInstance(DateFormat.SHORT, currentLocale);
return dateFormat.format(d);
}
示例15: formatStringDate
import java.text.DateFormat; //导入方法依赖的package包/类
public static String formatStringDate(String date){
String result = "";
if (date == null) return result;
DateFormat fmtOut = new SimpleDateFormat(MASK_PUBLISH_OUT, Locale.US);
DateFormat fmtIn = new SimpleDateFormat(MASK_PUBLISH_IN, Locale.US);
try {
Date dataParsed = fmtIn.parse(date);
result = fmtOut.format(dataParsed);
} catch (ParseException e) {
e.printStackTrace();
}
return result;
}