我想将长值转换为字符串或日期,格式为dd/mm/YYYY。
我有一个长格式的值: 1343805819061。
可以将其转换为日期格式吗?
发布于 2012-08-02 16:12:11
您可以使用下面的代码行来完成此操作。这里的timeInMilliSecond是长值。
String dateString = new SimpleDateFormat("MM/dd/yyyy").format(new Date(TimeinMilliSeccond));
或者你也可以使用下面的代码。
String longV = "1343805819061";
long millisecond = Long.parseLong(longV);
// or you already have long value of date, use this instead of milliseconds variable.
String dateString = DateFormat.format("MM/dd/yyyy", new Date(millisecond)).toString();
参考:- DateFormat和SimpleDateFormat
附注:根据您的需要更改日期格式。
发布于 2012-08-02 16:13:53
您可以在Date实例或contructor (Long)上使用setTime方法;
setTime(long time)
Sets this Date object to represent a point in time that is time milliseconds after January 1, 1970 00:00:00 GMT.
Date(long date)
Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT
然后使用简单的日期格式
请参阅http://docs.oracle.com/javase/1.4.2/docs/api/javax/swing/text/DateFormatter.html
发布于 2020-03-13 20:57:24
如果长度是10位,那么试试这个
long DateInLong= 1584212400;
Date date =新日期(DateInLong*1000L);
SimpleDateFormat simpledateformate=新SimpleDateFormat("yyyy-MM-dd");
String DATE =simpledateformate.format(日期);
https://stackoverflow.com/questions/11773369
复制相似问题