获取过程的开始时间 [英] Get Start Time of Process

查看:137
本文介绍了获取过程的开始时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的要求是,我想要找出所有正在运行的进程的开始时间和日期时间格式(DD / MM / YYYY HH:MM:SS)显示出来。

My requirement is that I want to find out the start time of all running processes and display it in Date Time Format (dd/mm/yyyy hh:mm:ss) .

我presently能够获得使用/ proc / [PID] / STAT特定处理的细节。这些细节包括开始时间命名的字段 - 不过,我想这是个jiffies。我如何使用这些细节显示过程的开始时间?

I am presently able to obtain the details of a particular process using /proc/[pid]/stat. These details include a field named starttime - however, I suppose it is in jiffies. How can I display the start time of process using these details ?

您的帮助将是非常美联社preciated。

Your help will be highly appreciated.

由于提前

推荐答案

有关获取日期和时间尝试这样的..

For to get Date and Time try like this ..

 String currentDateTime = (String) DateFormat.format("dd:MMMM:yyyy HH:mm:ss", new Date());

有关你的关心把这个,你永远需要启动过程中或在一些..这样的事。

For your concern put this where you start your process or where ever you need .. some thing like this ..

get_current_time = (Button) findViewById(R.id.time);
        get_current_time.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                /**
                 * @author vivek
                 */
                 String currentTime = (String) DateFormat.format("k:mm:ss", new Date());
                 Toast.makeText(getApplicationContext(), "Your current date and time is-" + currentTime, Toast.LENGTH_LONG).show();

                 //Calculating hour / minute / seconds of current time.
                 String hour = currentTime.split(":")[0];
                 String mint = currentTime.split(":")[1];
                 String sec = currentTime.split(":")[2];
                 Toast.makeText(getApplicationContext(), "Your current hour/mint/sec is :-" +hour + "/" + mint +"/" +sec, Toast.LENGTH_LONG).show();

                 // Converting all in seconds for further purpose. This needs to be changed on show time.
                 int total_time_in_second = Integer.parseInt(hour)*60*60 + Integer.parseInt(mint)*60 + Integer.parseInt(sec);
                 Toast.makeText(getApplicationContext(), "Your current total second is :- " + total_time_in_second, Toast.LENGTH_LONG).show();

            }
        });

希望它帮助。干杯

Hope it helps. Cheers

更新

当你需要启动任何程序的时间,然后只是尝试像....

When you need start time of any process then just try like ....

例如:当任何进程开始使用刚刚获得设备的时间。

Ex: When any process starts just get device time using ..

String currentDateTime = (String) DateFormat.format("dd:MMMM:yyyy HH:mm:ss", new Date());

这篇关于获取过程的开始时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆