當前位置: 首頁>>代碼示例>>Java>>正文


Java DateFormat.format方法代碼示例

本文整理匯總了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;
}
 
開發者ID:Datatellit,項目名稱:xlight_android_native,代碼行數:13,代碼來源:DateUtil.java

示例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);
}
 
開發者ID:rubenswagner,項目名稱:L2J-Global,代碼行數:16,代碼來源:Util.java

示例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;

}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:50,代碼來源:DateAxis.java

示例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));
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:14,代碼來源:TimeUtils.java

示例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);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:12,代碼來源:TCKLocalizedPrinterParser.java

示例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 "";
}
  }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:10,代碼來源:JspHelper.java

示例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;
    
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:46,代碼來源:BubbleXYItemLabelGenerator.java

示例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);
}
 
開發者ID:wintertime,項目名稱:FreeCol,代碼行數:11,代碼來源:HighScore.java

示例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);
}
 
開發者ID:xsonorg,項目名稱:tangyuan2,代碼行數:5,代碼來源:DateUtils.java

示例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);
}
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_06,代碼行數:7,代碼來源:TimeService.java

示例11: getMonth

import java.text.DateFormat; //導入方法依賴的package包/類
public String getMonth() {
    DateFormat finalFormat = new SimpleDateFormat("MM");
    return finalFormat.format(origDateTime);
}
 
開發者ID:adithya321,項目名稱:SOS-The-Healthcare-Companion,代碼行數:5,代碼來源:SplitDateTime.java

示例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);
}
 
開發者ID:guodroid,項目名稱:okwallet,代碼行數:10,代碼來源:Utils.java

示例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);
}
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_04,代碼行數:7,代碼來源:TimerServlet.java

示例14: 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,項目名稱:Reinickendorf_SER316,代碼行數:6,代碼來源:Local.java

示例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;
    }
 
開發者ID:victoraldir,項目名稱:BuddyBook,代碼行數:22,代碼來源:DateUtils.java


注:本文中的java.text.DateFormat.format方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。