本文整理汇总了Java中java.time.LocalDateTime.format方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDateTime.format方法的具体用法?Java LocalDateTime.format怎么用?Java LocalDateTime.format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.LocalDateTime
的用法示例。
在下文中一共展示了LocalDateTime.format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFormat4System
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* 使用系统自带的格式化格式
*/
@Test
public void testFormat4System() {
// 使用系统自带的格式化
DateTimeFormatter isoDateTimeFormatter = DateTimeFormatter.ISO_DATE_TIME;
DateTimeFormatter isoDateFormat = DateTimeFormatter.ISO_DATE;
// 获取当前时间
LocalDateTime now = LocalDateTime.now();
// 格式化1
String dateTimeFormat = now.format(isoDateTimeFormatter);
System.out.println(dateTimeFormat);
// 格式化2
String dateFormat = now.format(isoDateFormat);
System.out.println(dateFormat);
}
示例2: dynamicURIs
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void dynamicURIs() throws Throwable {
Path dynamic = new Path(fsUri.toString(), "${G}/${yyyy}/${MM}/${W}");
fs.create(dynamic);
Map<String, String> originals = taskConfig.originalsStrings();
originals.put(FsSourceTaskConfig.FS_URIS, dynamic.toString());
FsSourceTaskConfig cfg = new FsSourceTaskConfig(originals);
policy = ReflectionUtils.makePolicy((Class<? extends Policy>) taskConfig.getClass(FsSourceTaskConfig.POLICY_CLASS),
cfg);
assertEquals(1, policy.getURIs().size());
LocalDateTime dateTime = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("G");
StringBuilder uri = new StringBuilder(dateTime.format(formatter));
uri.append("/");
formatter = DateTimeFormatter.ofPattern("yyyy");
uri.append(dateTime.format(formatter));
uri.append("/");
formatter = DateTimeFormatter.ofPattern("MM");
uri.append(dateTime.format(formatter));
uri.append("/");
formatter = DateTimeFormatter.ofPattern("W");
uri.append(dateTime.format(formatter));
assertTrue(policy.getURIs().get(0).endsWith(uri.toString()));
}
示例3: insertIntoSchemaVersion
import java.time.LocalDateTime; //导入方法依赖的package包/类
/** Insere une version
* @param installedRank
* @param scriptFile
* @param installedOn
* @param executionTime
* @throws SQLException
* @throws MigrationException
*/
private void insertIntoSchemaVersion(int installedRank, String scriptFile, LocalDateTime installedOn, int executionTime) throws SQLException{
String path = "/db/migration/";
Pair<MigrationVersion, String> info =
MigrationInfoHelper.extractVersionAndDescription(scriptFile, flywayConfiguration.getSqlMigrationPrefix(), flywayConfiguration.getSqlMigrationSeparator(), flywayConfiguration.getSqlMigrationSuffix(), false);
ResolvedMigrationImpl migration = new ResolvedMigrationImpl();
migration.setVersion(info.getLeft());
migration.setDescription(info.getRight());
migration.setScript(scriptFile);
migration.setType(MigrationType.SQL);
String query = "INSERT INTO "+dbSupport.quote(flywayConfiguration.getTable())
+" VALUES ("+installedRank
+ ", '"+migration.getVersion()+"'"
+ ", '"+migration.getDescription()+"'"
+ ", '"+MigrationType.SQL+"'"
+ ", '"+scriptFile+"'"
+ ", "+calculateChecksum(path,scriptFile)
+ ", 'ecandidat'"
+ ", '" + installedOn.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) +"'"
+ ", "+executionTime
+ ", 1)";
jdbcTemplate.executeStatement(query);
}
示例4: Entry
import java.time.LocalDateTime; //导入方法依赖的package包/类
public Entry() {
this.entryTitle = new SimpleStringProperty("");
this.entryUsername = new SimpleStringProperty("");
this.entryPassword = new SimpleStringProperty("");
this.originalPassword = "";
LocalDateTime date = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yy-MM-dd HH:mm");
String formattedDate = date.format(formatter);
this.entryDate = new SimpleStringProperty(formattedDate);
}
示例5: AppContext
import java.time.LocalDateTime; //导入方法依赖的package包/类
public AppContext(Clock clock) throws IOException {
this.config = loadDefaultConfig();
this.webUIApp = new WebUIApp();
this.clock = clock;
LocalDateTime ldt0 = LocalDateTime.now(clock);
DateTimeFormatter dtf0 = DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss");
this.logContext = ldt0.format(dtf0);
}
示例6: onlyDate
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* 将一个Date解析成字符串 只保留年月日
* @param date
* @return
*/
public static String onlyDate(Date date) {
Instant milli = Instant.ofEpochMilli(date.getTime());
LocalDateTime ofInstant = LocalDateTime.ofInstant(milli, ZoneId.of("Asia/Shanghai"));
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
return ofInstant.format(formatter);
}
示例7: dateToString
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* This method returns as {@link String} the {@link LocalDateTime} passed as parameter using a {@link DateTimeFormatter}.
* @param date {@link LocalDateTime}
* @param formatter {@link DateTimeFormatter}
* @return {@link String}
* @throws JSKException if some of the parameters are null.
*/
public static String dateToString(LocalDateTime date, DateTimeFormatter formatter) throws JSKException {
if (isNull(date, formatter)) {
throw new JSKException(NULL_PARAMETERS);
}
return date.format(formatter);
}
示例8: dateTime
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* 将一个Date解析成yyyy-MM-dd HH:mm:ss格式的字符串
* @param date
* @return
*/
public static String dateTime(Date date) {
Instant milli = Instant.ofEpochMilli(date.getTime());
LocalDateTime ofInstant = LocalDateTime.ofInstant(milli, ZoneId.of("Asia/Shanghai"));
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
return ofInstant.format(formatter);
}
示例9: initData
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* Add a highscore to the HighScores.xml.
* @param player Name of the player.
* @param score The reached score.
*/
public static void initData(String player, int score) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
LocalDateTime dateTime = LocalDateTime.now();
String formattedDateTime = dateTime.format(formatter);
HighScore highScore = new HighScore(player, String.valueOf(score), formattedDateTime);
HighScoreDAOImp higshScoreDAO = new HighScoreDAOImp();
higshScoreDAO.addHighScore(highScore);
}
示例10: convertLongToDateTime
import java.time.LocalDateTime; //导入方法依赖的package包/类
public String convertLongToDateTime(Long millis, String pattern) {
final LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(millis), ZoneId.systemDefault());
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
return localDateTime.format(formatter);
}
示例11: toString
import java.time.LocalDateTime; //导入方法依赖的package包/类
public static String toString(LocalDateTime time, String pattern) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
return time.format(formatter);
}
示例12: setPanel
import java.time.LocalDateTime; //导入方法依赖的package包/类
private void setPanel(){
String currentClass = jComboBox1.getSelectedItem().toString();
LocalDateTime currentDateTime = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM dd, yyyy");
String date = currentDateTime.format(formatter);
//the above lines inspired by those on https://www.mkyong.com/java8/java-8-how-to-format-localdatetime/
jLabel6.setText(date);
///if professor
boolean quizToday = true;
boolean quizDone= false;
boolean quizNotStarted= false;
boolean quizInProgress = true;
//check quiz start/end time for above.
if(!quizToday){
jLabel8.setText("You have not set a quiz today");
jButton3.setVisible(false);
}
else if(quizDone){
jLabel8.setText("Today's quiz is done, click to view results");
jButton3.setVisible(true);
}
else if(quizNotStarted){
jLabel8.setText("Today's quiz hasn't started, click to edit");
jButton3.setVisible(true);
jButton3.setText("Edit");
}
else if(quizInProgress){
jLabel8.setText("Quiz in progress, click to view results");
jButton3.setVisible(true);
}
//determine if searching by date or by student
formatter = DateTimeFormatter.ofPattern("MM-dd-yyyy");
date = currentDateTime.format(formatter);
jTextField1.setText(date);
jTextField2.setText(date);
//if student
}
示例13: dateTimeNow
import java.time.LocalDateTime; //导入方法依赖的package包/类
public static String dateTimeNow() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime dateTime = LocalDateTime.now();
String formattedDateTime = dateTime.format(formatter) + ": ";
return formattedDateTime;
}
示例14: getContainerCreationTime
import java.time.LocalDateTime; //导入方法依赖的package包/类
public String getContainerCreationTime ( Container container ) {
long secondsSinceEpoch = container.getCreated();
LocalDateTime createDT = LocalDateTime.ofInstant( Instant.ofEpochMilli( secondsSinceEpoch * 1000 ), ZoneId.systemDefault() );
return createDT.format( DateTimeFormatter.ofPattern( "HH:mm:ss MMM d, yyyy" ) );
}
示例15: marshal
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Nullable
@Override
public String marshal(LocalDateTime v) {
return v == null ? null : v.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"));
}