當前位置: 首頁>>代碼示例>>Java>>正文


Java LocalDateTime.format方法代碼示例

本文整理匯總了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);
}
 
開發者ID:cbooy,項目名稱:cakes,代碼行數:21,代碼來源:DateTimeFormatterDemo.java

示例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()));

}
 
開發者ID:mmolimar,項目名稱:kafka-connect-fs,代碼行數:27,代碼來源:PolicyTestBase.java

示例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);
}
 
開發者ID:EsupPortail,項目名稱:esup-ecandidat,代碼行數:33,代碼來源:FlywayCallbackMigration.java

示例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);
}
 
開發者ID:yc45,項目名稱:kanphnia2,代碼行數:13,代碼來源:Entry.java

示例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);
}
 
開發者ID:SecureSkyTechnology,項目名稱:burpextender-proxyhistory-webui,代碼行數:9,代碼來源:AppContext.java

示例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);
}
 
開發者ID:NymphWeb,項目名稱:nymph,代碼行數:12,代碼來源:DateUtil.java

示例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);
}
 
開發者ID:Varoso,項目名稱:JSK,代碼行數:16,代碼來源:JSKDateConverter.java

示例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);
}
 
開發者ID:NymphWeb,項目名稱:nymph,代碼行數:12,代碼來源:DateUtil.java

示例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);
}
 
開發者ID:madar94,項目名稱:FlappySpaceShip,代碼行數:15,代碼來源:Main.java

示例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);
}
 
開發者ID:Naoghuman,項目名稱:ABC-List,代碼行數:7,代碼來源:DateConverter.java

示例11: toString

import java.time.LocalDateTime; //導入方法依賴的package包/類
public static String toString(LocalDateTime time, String pattern) {
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
    return time.format(formatter);
}
 
開發者ID:shibing624,項目名稱:phrase-search,代碼行數:5,代碼來源:TimeUtil.java

示例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
    
}
 
開發者ID:karanjadhav2508,項目名稱:kqsse17,代碼行數:51,代碼來源:homescreen.java

示例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;
}
 
開發者ID:polygOnetic,項目名稱:guetzliconverter,代碼行數:7,代碼來源:ProcessExecutor.java

示例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" ) );
	}
 
開發者ID:csap-platform,項目名稱:csap-core,代碼行數:7,代碼來源:DockerHelper.java

示例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"));
}
 
開發者ID:dvbern,項目名稱:date-helper,代碼行數:6,代碼來源:LocalDateTimeXMLConverter.java


注:本文中的java.time.LocalDateTime.format方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。