Getting difference between two dates Android

后端 未结 6 1809
故里飘歌
故里飘歌 2020-12-01 22:05

Am having string posting date like :

2011-03-27T09:39:01.607

and There is current date .

I want to get difference between these tw

6条回答
  •  醉话见心
    2020-12-01 22:51

    You can use getRelativeTimeSpanString(). It returns a string like "1 minute ago". Here is a real simple example that tells how long the application has been running.

    private long mStartTime;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mStartTime = System.currentTimeMillis();
    }
    
    public void handleHowLongClick(View v) {
        CharSequence cs = DateUtils.getRelativeTimeSpanString(mStartTime);
        Toast.makeText(this, cs, Toast.LENGTH_LONG).show();
    }
    

提交回复
热议问题