开发者

PackageManager issue in android

开发者 https://www.devze.com 2023-03-11 22:56 出处:网络
I can\'t get date in properManner, I use PackageManager: Code example ::List<PackageInfo> applications = getPackageManager().getInstalledPackages(0);

I can't get date in properManner, I use PackageManager:

Code example

::List<PackageInfo> applications = getPackageManager().getInstalledPackages(0);
        for(PackageInfo info : applications){
          //  Drawable icon = info.applicationInfo.loadIcon(getBaseContext());
            long firstInstalled = info.firstInstallTime;
            long lastUpdate = info.lastUpdateTime;
            System.out.pr开发者_运维知识库intln("firstInstalled"+firstInstalled);

if I print firstInstalled to LOGCAT then I got result "firstInstalled is 1305907770197" I can't able to understand what is this? can you help me?


Look right there in your code. It says long firstInstalled = info.firstInstallTime;. It is a number representing the number of milliseconds since January 1, 1970 00:00:00 UTC.

Maybe you want a more readable representation of that info?

Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(firstInstalled);

Now you can extract and display the values for hour, day, year, etc. from the cal variable. See Calendar for further info.


Use below code

Date d = new Date(firstInstalled);
d.getDate();
d.getMonth();
d.getYear();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号