Skip to content

Instantly share code, notes, and snippets.

@Tarelochkin
Created October 7, 2017 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tarelochkin/57296cf655011de21a21d31d39490464 to your computer and use it in GitHub Desktop.
Save Tarelochkin/57296cf655011de21a21d31d39490464 to your computer and use it in GitHub Desktop.
<string name="countDownFormat" >%1$02d:%2$02d</string>
<string name="timeFormat">hh:mm a</string>
//process current time in milliseconds into "00:00 am" format
Timestamp currentTime = new Timestamp(System.currentTimeMillis());
SimpleDateFormat formatter = new SimpleDateFormat(getString(R.string.timeFormat), Locale.getDefault());
String currentTimeString = formatter.format(currentTime);
//process a number of minutes into "hh:mm" format
long totalMinutesCount = 123;
long hoursCount = TimeUnit.MINUTES.toHours(totalMinutesCount);
long minutesLessHoursCount =
totalMinutesCount - TimeUnit.HOURS.toMinutes(hoursCount);
//will produce "02:03"
String hoursAndMinutesCount = getString(R.string.countDownFormat,
hoursCount,
minutesLessHoursCount);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment