Current timestamp as filename in Java

前端 未结 7 1643

I want to name new files created by my Java application with the current timestamp.

I need help with this. How do I name the new files created with the current timestamp

7条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-03 17:51

    You can use DateTime

    import org.joda.time.DateTime
    

    Option 1 : with yyyyMMddHHmmss

    DateTime.now().toString("yyyyMMddHHmmss")
    

    Will give 20190205214430

    Option 2 : yyyy-dd-M--HH-mm-ss

       DateTime.now().toString("yyyy-dd-M--HH-mm-ss")
    

    will give 2019-05-2--21-43-32

提交回复
热议问题