How to get current timestamp in string format in Java? “yyyy.MM.dd.HH.mm.ss”

前端 未结 7 841
天涯浪人
天涯浪人 2020-12-04 06:27

How to get timestamp in string format in Java? \"yyyy.MM.dd.HH.mm.ss\"

String timeStamp = new SimpleDateFormat(\"yyyy.MM.dd.HH.mm.ss\").format(new Timestamp(         


        
7条回答
  •  死守一世寂寞
    2020-12-04 07:14

    A more appropriate approach is to specify a Locale region as a parameter in the constructor. The example below uses a US Locale region. Date formatting is locale-sensitive and uses the Locale to tailor information relative to the customs and conventions of the user's region Locale (Java Platform SE 7)

    String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss", Locale.US).format(new Date());
    

提交回复
热议问题