简体   繁体   English

用法语将长时间时间戳转换为Java.util.Date

[英]Convert long timestamp to Java.util.Date in french

I want to know how I can convert a timestamp in the date format. 我想知道如何转换日期格式的时间戳。 For example : 1415337782000 should be converted to "7 nov. 2014". 例如:1415337782000应该转换为“ 2014年11月7日”。

This is what I've tried so far : 到目前为止,这是我尝试过的:

Date date=new Date(location.date);
SimpleDateFormat df = (SimpleDateFormat) SimpleDateFormat.getDateInstance(SimpleDateFormat.MEDIUM);
String dateText = df.format(date);

The timestamp is stored in location.date in long type. 时间戳以long类型存储在location.date中。

Thanks in advance for your help. 在此先感谢您的帮助。

You can pass a format to the SimpleDateFormat constructor, like this 您可以将格式传递给SimpleDateFormat构造函数,如下所示

SimpleDateFormat format= new SimpleDateFormat("d MMM, yyyy");
String dateText = format.format(new Date());

You can find the constants in this link: 您可以在此链接中找到常量:

http://developer.android.com/reference/java/text/SimpleDateFormat.html http://developer.android.com/reference/java/text/SimpleDateFormat.html

For better internationalization, you can define a string resource containing the desired format based on the location of the user. 为了更好的国际化,您可以根据用户的位置定义一个包含所需格式的字符串资源。 Something like 就像是

SimpleDateFormat  format = new SimpleDateFormat(getResources().getString(R.string.YOUR_FORMAT));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM