-2

I need to convert a String which is a epoch (Unix time) format to a Date class an after a String formatted (dd/MM/yyyy).

Thank you for your help !

L. Quastana
  • 1,273
  • 1
  • 12
  • 34
  • 1
    You should post what you have tried so far. We're not going to make your work for you as you surely understand. – m0skit0 Jul 18 '13 at 11:39
  • Welcome to StackOverflow. Questions about parsing and formatting dates are one of the most common type of Java questions here. Please do a seach, you'll find lots of answers. – Jesper Jul 18 '13 at 11:49
  • For example: http://stackoverflow.com/questions/535004/unix-epoch-time-to-java-date-object?lq=1 – Jesper Jul 18 '13 at 11:50

2 Answers2

6

Unix time is the number of seconds since 1 January 1970, so this should work

Date date = new Date(unixTime * 1000);
String str = new SimpleDateFormat("dd/MM/yyyy").format(date);

BTW SimpleDateFormat accepts millis as argument too, so it is possible to get the same result as

String str = new SimpleDateFormat("dd/MM/yyyy").format(unixTime * 1000);
Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275
1
    Date date = new Date(time);
    DateFormat format = new SimpleDateFormat("dd/MM/yyyy");
    format.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
    String formatted = format.format(date);
    System.out.println(formatted);
blganesh101
  • 3,647
  • 1
  • 24
  • 44