本文整理了Java中java.text.SimpleDateFormat.format()
方法的一些代码示例,展示了SimpleDateFormat.format()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SimpleDateFormat.format()
方法的具体详情如下:
包路径:java.text.SimpleDateFormat
类名称:SimpleDateFormat
方法名:format
[英]Formats the specified date as a string using the pattern of this date format and appends the string to the specified string buffer.
If the field member of field contains a value specifying a format field, then its beginIndex and endIndex members will be updated with the position of the first occurrence of this field in the formatted text.
[中]使用此日期格式的模式将指定的日期格式化为字符串,并将该字符串附加到指定的字符串缓冲区。
如果字段的字段成员包含指定格式字段的值,则其beginIndex和endIndex成员将更新为该字段在格式化文本中第一次出现的位置。
代码示例来源:origin: alibaba/druid
public static String toString(java.util.Date date) {
if (date == null) {
return null;
}
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return format.format(date);
}
代码示例来源:origin: redisson/redisson
/**
* Formats time to HTTP date/time format. Note that number of milliseconds
* is lost.
*/
public static String formatHttpDate(long millis) {
Date date = new Date(millis);
return HTTP_DATE_FORMAT.format(date);
}
代码示例来源:origin: Netflix/eureka
public static String getCurrentTimeAsString() {
SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
return format.format(new Date());
}
}
代码示例来源:origin: alibaba/canal
public final String formatUTCTZ(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
return sdf.format(date);
}
代码示例来源:origin: north2016/T-MVP
public static List<String> getOldWeekDays() {
final Calendar c = Calendar.getInstance();
String[] months = new String[8];
for (int i = 0; i < 8; i++) {
months[i] = new SimpleDateFormat("MM.dd").format(new Date(c
.getTimeInMillis()));
c.add(Calendar.DAY_OF_MONTH, -1);
}
return Arrays.asList(months);
}
代码示例来源:origin: weibocom/motan
private void printStartInfo() {
Date currentDate = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(currentDate);
calendar.add(Calendar.SECOND, runTime);
Date finishDate = calendar.getTime();
StringBuilder startInfo = new StringBuilder(dateFormat.format(currentDate));
startInfo.append(" ready to start client benchmark");
startInfo.append(", concurrent num is ").append(concurrents);
startInfo.append(", the benchmark will end at ").append(dateFormat.format(finishDate));
System.out.println(startInfo.toString());
}
代码示例来源:origin: gocd/gocd
public static String dateToString(Date date) {
if (date != null) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_PATTERN);
simpleDateFormat.setTimeZone(UTC);
return simpleDateFormat.format(date);
}
return "";
}
}
代码示例来源:origin: openhab/openhab1-addons
@Override
public String toString() {
return new SimpleDateFormat(DATE_PATTERN).format(calendar.getTime());
}
代码示例来源:origin: org.apache.commons/commons-lang3
private void checkParse(final Locale locale, final Calendar cal, final SimpleDateFormat sdf, final DateParser fdf) throws ParseException {
final String formattedDate= sdf.format(cal.getTime());
checkParse(locale, sdf, fdf, formattedDate);
checkParse(locale, sdf, fdf, formattedDate.toLowerCase(locale));
checkParse(locale, sdf, fdf, formattedDate.toUpperCase(locale));
}
代码示例来源:origin: apache/rocketmq
public String getCurTime() {
String fromTimeZone = "GMT+8";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
format.setTimeZone(TimeZone.getTimeZone(fromTimeZone));
String chinaDate = format.format(date);
return chinaDate;
}
代码示例来源:origin: Netflix/eureka
public static String getCurrentTimeAsString() {
SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
return format.format(new Date());
}
}
代码示例来源:origin: PhilJay/MPAndroidChart
@Override
public String getFormattedValue(float value) {
long millis = TimeUnit.HOURS.toMillis((long) value);
return mFormat.format(new Date(millis));
}
});
代码示例来源:origin: elastic/elasticsearch-hadoop
@Test
public void testCalendar() {
Date d = new Date(0);
Calendar cal = Calendar.getInstance();
cal.setTime(d);
assertThat(jdkTypeToJson(cal), containsString(new SimpleDateFormat("yyyy-MM-dd").format(d)));
}
代码示例来源:origin: gocd/gocd
public static String dateToString(Date date) {
if (date != null) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_PATTERN);
simpleDateFormat.setTimeZone(UTC);
return simpleDateFormat.format(date);
}
return "";
}
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public void encode(Object obj, JSONWriter jb) throws IOException {
jb.valueString(new SimpleDateFormat(DATE_FORMAT).format((Date) obj));
}
};
代码示例来源:origin: openhab/openhab1-addons
@Override
public String format(String pattern) {
try {
return String.format(pattern, calendar);
} catch (NullPointerException npe) {
return new SimpleDateFormat(DATE_PATTERN).format(calendar.getTime());
}
}
代码示例来源:origin: org.testng/testng
/**
* @param timeInMilliSeconds - The time in milliseconds
* @param format - A format that can be used by {@link SimpleDateFormat}
* @return - A formatted string representation of the time in UTC/GMT timezone.
*/
public static String timeInUTC(long timeInMilliSeconds, String format) {
SimpleDateFormat sdf = new SimpleDateFormat(format);
TimeZone utc = TimeZone.getTimeZone("UTC");
sdf.setTimeZone(utc);
return sdf.format(timeInMilliSeconds);
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
/**
* Returns a String representing the current date and time in the given
* format.
*
* @see <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat</a>
*/
public static String getTimestampString(String fmt) {
return (new SimpleDateFormat(fmt)).format(new Date());
}
代码示例来源:origin: ch.qos.logback/logback-classic
String computeTimeStampString(long now) {
synchronized (this) {
// Since the formatted output is only precise to the second, we can use the same cached string if the
// current
// second is the same (stripping off the milliseconds).
if ((now / 1000) != lastTimestamp) {
lastTimestamp = now / 1000;
Date nowDate = new Date(now);
calendar.setTime(nowDate);
timesmapStr = String.format("%s %2d %s", simpleMonthFormat.format(nowDate), calendar.get(Calendar.DAY_OF_MONTH),
simpleTimeFormat.format(nowDate));
}
return timesmapStr;
}
}
}
代码示例来源:origin: com.h2database/h2
String getStartDateTime() {
if (startDateTime == null) {
SimpleDateFormat format = new SimpleDateFormat(
"EEE, d MMM yyyy HH:mm:ss z", new Locale("en", ""));
format.setTimeZone(DateTimeUtils.UTC);
startDateTime = format.format(System.currentTimeMillis());
}
return startDateTime;
}
内容来源于网络,如有侵权,请联系作者删除!