How can I set date and time formatting in Java that respects the user's OS settings

后端 未结 7 930
Happy的楠姐
Happy的楠姐 2020-11-28 11:25

I am running my Java app on a Windows 7 machine where my regional settings are set up to format dates as YYYY-mm-dd and time as HH:mm:ss (e.g. \"2011-06-20 07:50:28\"). But

7条回答
  •  青春惊慌失措
    2020-11-28 11:48

    Perhaps I'm misunderstanding what you're getting at here but you need to use the Locale.

     DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.FRANCE);
    

    By using Locale you can control what format for what region you're using.

提交回复
热议问题