12

how to get current date in DD-MM-YYYY format in BlackBerry

i have already tried the following, but it gives me output of 1318502493

long currentTime = System.currentTimeMillis() / 1000;

System.out.println("Current time in :" + currentTime);
Michael Donohue
  • 11,776
  • 5
  • 31
  • 44
Hitarth
  • 1,950
  • 3
  • 27
  • 52

3 Answers3

26
private String pattern = "dd-MM-yyyy";
String dateInString =new SimpleDateFormat(pattern).format(new Date());
Balconsky
  • 2,234
  • 3
  • 26
  • 39
8
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
return formatter.format(new Date());
Nathan Q
  • 1,892
  • 17
  • 40
3

Check if you can use SimpleDateFormat. If you can, create an object of this class, and use it in order to format the return provided by System.currentTimeMillis(). Some code below:

import java.util.*;
import java.text.*;

public class DateTest {
  public static String getCurrentTimeStamp() {
       SimpleDateFormat formDate = new SimpleDateFormat("dd-MM-yyyy");

       // String strDate = formDate.format(System.currentTimeMillis()); // option 1
       String strDate = formDate.format(new Date()); // option 2
       return strDate;
  } 
  public static void main (String args[]) {
       System.out.println(getCurrentTimeStamp());
  }
}
Moacir Ponti
  • 591
  • 5
  • 14