本文整理匯總了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);
}