-1

I am converting timestamp to Solar Hijri and good work like bellow :

    private String getDate(long timestamp) {
        Date date = new Date(timestamp * 1000L);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd/HH:mm", Locale.UK);
        String[] paths = sdf.format(date).split("/");
        CalendarTool ct = new CalendarTool(Integer.parseInt(paths[0]),
                Integer.parseInt(paths[1]),
                Integer.parseInt(paths[2]));
        return ct.getIranianDate().trim() + " - " + paths[3].trim();
    }

Problem: I get time base 24 hours but when I have 12:45 or 24:13 show me 00:45 and 00:13 always, but I need to 12:45 and 00:13.

I have problem with 12 and 00 .

For example my timestamp is : 1515186060

  • @ Noise Generator . Sorry 00:13 . –  Jan 06 '18 at 11:40
  • 1
    This format looks very weird to me: `"yyyy/MM/dd/HH:mm"` You normally use the ISO standard `"yyyy-MM-ddTHH:mm"`. Or one of its variants (with/out seconds and/or timezone). – Phantômaxx Jan 06 '18 at 11:42
  • As an aside consider throwing away the long outmoded and notoriously troublesome `SimpleDateFormat` and friends, and adding [ThreeTenABP](https://github.com/JakeWharton/ThreeTenABP) to your Android project in order to use `java.time`, the modern Java date and time API. It is so much nicer to work with. – Ole V.V. Jan 08 '18 at 09:35
  • I cannot reproduce. Your `sdf` gives me 12:45 and 00:13, exactly as you said you need. – Ole V.V. Jan 08 '18 at 11:33

1 Answers1

0

You can use kk to do that

simpDate = new SimpleDateFormat("kk:mm:ss");

If you use kk you will get results like 24:30 but if you use HH you can get it like 00:30.
Or simply create the instance of Calendar and get 24 hr time by,

Calendar c = Calendar.getInstance();

int Hr24 = c.get(Calendar.HOUR_OF_DAY);
int Min = c.get(Calendar.MINUTE);
A Pishma
  • 31
  • 7