本文整理汇总了Java中java.text.SimpleDateFormat.format方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleDateFormat.format方法的具体用法?Java SimpleDateFormat.format怎么用?Java SimpleDateFormat.format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.SimpleDateFormat
的用法示例。
在下文中一共展示了SimpleDateFormat.format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dateToString
import java.text.SimpleDateFormat; //导入方法依赖的package包/类
/**
* Convertit une date (java.util.Date) vers une représentation String construite avec le
* format demandé.
*
* @param date une date de la classe java.util.Date
* @param format un format de date (ou de temps) sous la forme d'un String
* @return la même date au format String
*/
public static String dateToString(Date date, String format) {
String sDate = "...";
if (date != null) {
SimpleDateFormat ldf = getLocaleFormat(format);
sDate = ldf.format(date);
}
return sDate;
}
示例2: addMonth
import java.text.SimpleDateFormat; //导入方法依赖的package包/类
/**
* 原有日期上累加月
*
* @return 累加后的日期 PATTERN_DATE 部分
*/
public static String addMonth(String date, int moonCount) {
//如果date为空 就用当前时间
if (TextUtils.isEmpty(date)) {
SimpleDateFormat df = new SimpleDateFormat(PATTERN_DATE + PATTERN_SPLIT + PATTERN_TIME);
date = df.format(new Date());
}
Calendar calendar = str2calendar(date);
calendar.add(Calendar.MONTH, moonCount);
return getDate(calendar2str(calendar));
}
示例3: testExportLogsForLogLevelWithUPTOLOGLEVEL
import java.text.SimpleDateFormat; //导入方法依赖的package包/类
@Test
public void testExportLogsForLogLevelWithUPTOLOGLEVEL() throws IOException {
setupForExportLogs();
Date startDate = new Date(System.currentTimeMillis() - 2 * 60 * 1000);
SimpleDateFormat sf = new SimpleDateFormat("yyyy/MM/dd");
String start = sf.format(startDate);
Date enddate = new Date(System.currentTimeMillis() + 2 * 60 * 60 * 1000);
String end = sf.format(enddate);
String dir = getCurrentTimeString();
String logLevel = LogWriterImpl.levelToString(LogWriterImpl.SEVERE_LEVEL);
MiscellaneousCommands misc = new MiscellaneousCommands();
getCache();
Result cmdResult =
misc.exportLogsPreprocessing("./testExportLogsForLogLevelWithUPTOLOGLEVEL" + dir, null,
null, logLevel, true, false, start, end, 1);
getLogWriter().info("testExportLogsForLogLevelWithUPTOLOGLEVEL command=" + cmdResult);
if (cmdResult != null) {
String cmdStringRsult = commandResultToString((CommandResult) cmdResult);
getLogWriter()
.info("testExportLogsForLogLevelWithUPTOLOGLEVEL cmdStringRsult=" + cmdStringRsult);
assertEquals(Result.Status.OK, cmdResult.getStatus());
} else {
fail("testExportLogsForLogLevelWithUPTOLOGLEVEL failed as did not get CommandResult");
}
FileUtil.delete(new File("testExportLogsForLogLevelWithUPTOLOGLEVEL" + dir));
}
示例4: getFormattedDate
import java.text.SimpleDateFormat; //导入方法依赖的package包/类
private String getFormattedDate(long milliseconds) {
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTimeInMillis(milliseconds);
SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
return dateFormat.format(calendar.getTime());
}
示例5: getDate
import java.text.SimpleDateFormat; //导入方法依赖的package包/类
public static String getDate() throws Exception
{
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
String DateNow = dateFormat.format(date);
return DateNow;
}
示例6: getFormatCreationDate
import java.text.SimpleDateFormat; //导入方法依赖的package包/类
public String getFormatCreationDate() {
Date date = getCreationDate();
String str = null;
if ( date != null ) {
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssZ" );
str = sdf.format( date );
}
return str;
}
示例7: getNowYMD
import java.text.SimpleDateFormat; //导入方法依赖的package包/类
/**
* MM-dd
* @return
*/
@SuppressLint("SimpleDateFormat")
public static String getNowYMD(){
SimpleDateFormat mDateFormat = new SimpleDateFormat(
"yyyy-MM-dd");
String date = mDateFormat.format(new Date());
return date;
}
示例8: testStartupTimestamp
import java.text.SimpleDateFormat; //导入方法依赖的package包/类
@Test
public void testStartupTimestamp() throws Exception
{
Substitutions subs = new Substitutions(TEST_DATE, 0);
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
String expected = formatter.format(new Date(runtimeMxBean.getStartTime()));
assertEquals(expected, subs.perform("{startupTimestamp}"));
}
示例9: timeFormatYYYYMMDD
import java.text.SimpleDateFormat; //导入方法依赖的package包/类
public static String timeFormatYYYYMMDD(String time) {
//
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
Date date = null;
try {
// 将给定的字符串中的日期提取出来
date = sdf.parse(time);
} catch (Exception e) {
DebugUtil.debug("--时间解析-->", "错误");
return time;
}
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
return sdf1.format(date);
}
示例10: formatDate
import java.text.SimpleDateFormat; //导入方法依赖的package包/类
public static String formatDate(Date date, String format, Locale locale) {
SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
return sdf.format(date);
}
示例11: getPartString
import java.text.SimpleDateFormat; //导入方法依赖的package包/类
public String getPartString(Session session, Object dateTime, int part) {
String javaPattern = "";
switch (part) {
case DAY_NAME :
javaPattern = "EEEE";
break;
case MONTH_NAME :
javaPattern = "MMMM";
break;
}
SimpleDateFormat format = session.getSimpleDateFormatGMT();
try {
format.applyPattern(javaPattern);
} catch (Exception e) {}
Date date = (Date) convertSQLToJavaGMT(session, dateTime);
return format.format(date);
}
示例12: getCurrentDateString
import java.text.SimpleDateFormat; //导入方法依赖的package包/类
/**
* 获取当前日期字符串
* @return
*/
public static String getCurrentDateString() {
SimpleDateFormat df = new SimpleDateFormat("yyyy年MM月dd日");
return df.format(new Date());
}
示例13: getStringDateShort
import java.text.SimpleDateFormat; //导入方法依赖的package包/类
public static String getStringDateShort() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = formatter.format(currentTime);
return dateString;
}
示例14: formatNow
import java.text.SimpleDateFormat; //导入方法依赖的package包/类
public static String formatNow() {
SimpleDateFormat format = new SimpleDateFormat("MM-dd HH:mm:ss", Locale.getDefault());
return format.format(System.currentTimeMillis());
}
示例15: format
import java.text.SimpleDateFormat; //导入方法依赖的package包/类
public static String format(Date date){
SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-d:HH-mm:ss");
return sdf.format(date);
}