」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > 如何在Java中將DD/MM/YYYY轉換為Yyyy/mm/dd日期格式?

如何在Java中將DD/MM/YYYY轉換為Yyyy/mm/dd日期格式?

發佈於2025-03-23
瀏覽:357

How to Convert dd/MM/yyyy to yyyy/MM/dd Date Format in Java?

Changing Date Format in Java: Transforming dd/MM/yyyy to yyyy/MM/dd

To alter the date format from dd/MM/yyyy to yyyy/MM/dd in Java, you can utilize the SimpleDateFormat class.以下是繼續進行的方法:

將原始和新的日期格式定義為字符串常數:
    考慮原始日期字符串,例如:
  1. 使用原始格式創建一個simpleDateFormat對象:
final String OLD_FORMAT = "dd/MM/yyyy";
final String NEW_FORMAT = "yyyy/MM/dd";
  1. Subsequently, adapt the SimpleDateFormat object to use the new format:
String oldDateString = "12/08/2010"; // Assuming August 12, 2010
  1. Finally, format the Date object using the updated SimpleDateFormat object to obtain the new date string:
SimpleDateFormat sdf = new SimpleDateFormat(OLD_FORMAT);
    This approach allows you to successfully convert the date string from the original format (dd/MM/yyyy) to the desired format (yyyy/MM/dd).
最新教學 更多>

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3