gpt4 book ai didi

android 获取毫秒级的日期

转载 作者:行者123 更新时间:2023-11-30 01:42:23 25 4
gpt4 key购买 nike

我有一个以毫秒为单位的 future 日期,我想将其转换为这样的“日历实例”:

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);

希望您理解我的问题,非常感谢您的帮助。

最佳答案

请按要求使用此方法,

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());
}
}

关于android 获取毫秒级的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34287087/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com