当前位置: 首页>>代码示例>>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;未经允许,请勿转载。