我的未来日期以毫秒为单位,我希望将其转换为“日历实例”,如下所示:
long FutureDateinMilliSeconds = System.currentTimeMillis() + 68435123141;
Calendar calToday = Calendar.getInstance();
calToday.set(Calendar.YEAR, YEAR VALUE OF FutureDateinMilliSeconds );
calToday.set(Calendar.MONTH, MONTH VALUE OF FutureDateinMilliSeconds);
calToday.set(Calendar.DATE, DAY VALUE OF FutureDateinMilliSeconds);
calToday.set(Calendar.HOUR_OF_DAY, 0);
calToday.set(Calendar.MINUTE, 0);
calToday.set(Calendar.SECOND, 0);
calToday.set(Calendar.MILLISECOND, 0);
我希望你理解我的问题,非常感谢你的帮助。
答案 0 :(得分:1)
请根据要求使用此方法,
public static String getDate(long milliSeconds, String dateFormat)
{
// Create a DateFormatter object for displaying date in specified format.
SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
// Create a calendar object that will convert the date and time value in milliseconds to date.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(milliSeconds);
return formatter.format(calendar.getTime());
}
}
答案 1 :(得分:0)
这是您在android
中将日期作为日期对象所需要做的 long FutureDateinMilliSeconds = System.currentTimeMillis() + 68435123141l;
Date fDate = new Date(FutureDateinMilliSeconds );
如果您想要特定格式的日期,可以使用
String fDate = new SimpleDateFormat("yyyy-MM-dd").format(cDate);