当前位置: 首页>>代码示例>>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;未经允许,请勿转载。