0

Currently I am Using DateFormat to convert Current Date, then I get the output like 8/27/12 (month/day/year).
But I want to display like this Today, Yesterday.
How to make this?
Please help me

I tried this:

long dtMili = System.currentTimeMillis();        
Date d = new Date(dtMili);  
java.text.DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext());    
System.out.println("DATE FORMAT  "+ dateFormat.format(d));

Using Dateformat in iPhone:

NSString *dateString = [self getNaturalDay:CurrentDate];
SampathKumar
  • 2,525
  • 8
  • 47
  • 82
  • I have no idea what you're asking. Please clarify your question. – JoxTraex Aug 27 '12 at 06:45
  • Actually i want like this for how many members are message to day and yesterday so that – SampathKumar Aug 27 '12 at 06:49
  • But i tried to convert only 8/27/12 (month/day/year) this way – SampathKumar Aug 27 '12 at 06:49
  • I don't think so that there is any method to change date like your requirement without using your own logic. You can create some methods which will calculate dates for today, tomorrow, yesterday etc.. and then you can pass that date to your message calculator method. – Pankaj Kumar Aug 27 '12 at 06:56

2 Answers2

0

Why don't you compare dates and make a string to show in your page. else below is some reference for you

See this question/answersHow to get date in Today, Yesterday format

as par suggestion in that answer, you should use this library

Community
  • 1
  • 1
AAnkit
  • 27,299
  • 12
  • 60
  • 71
0

This will help you:

Edit:

    @Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    long dtMili = System.currentTimeMillis();
    CharSequence d =DateUtils.getRelativeTimeSpanString(dtMili);
    Toast.makeText(this, d, Toast.LENGTH_LONG).show();

   }

Try to run this code. It will display "0 minutes ago",Instead of displaying some date format and depending upon ur logic it will display the time in its realtive form(i.e. 12 hours ago, yesterday, 3 days ago e.t.c.). This way of displaying time is called Relative time display.

Deadlock

Mohit
  • 2,940
  • 2
  • 24
  • 32
  • @Minu just pass the time value(i.e long) u getting in this line of code and set the above value as final value and display it. – Mohit Aug 27 '12 at 07:07
  • Can u please give simple exampl for this, becoz i didn'y understand. – SampathKumar Aug 27 '12 at 07:13
  • @Minu If my solution is what, that you were looking for then pls accept this as an answer. So that it may help someone else facing the same issue. – Mohit Aug 27 '12 at 07:57
  • Thank you, this comes like 0 second ago, but i want today, yesterday . – SampathKumar Aug 27 '12 at 11:08
  • It will surely show the time as today,yesterday. Its showing o sec ago is bcoz i have used system.currentMilliSeconds(); which giving the current system time(Just to give u an example). – Mohit Aug 27 '12 at 11:44
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/15848/discussion-between-deadlock-and-minu) – Mohit Aug 27 '12 at 11:46