Java Utililty Methods Second Format

List of utility methods to do Second Format

Description

The list of methods to do Second Format are organized into topic(s).

Method

voidprintElapsedSeconds(long start)
print Elapsed Seconds
long stop = System.currentTimeMillis();
double difference = (stop - start);
double seconds = difference / 1000;
NumberFormat format = NumberFormat.getNumberInstance();
String beautified = format.format(seconds);
System.out.println(beautified + " seconds");
StringremoveSecondsFromDateString(String sdate)
Removes seconds from string for view in list.
return sdate.substring(0, sdate.lastIndexOf(":"));
StringSecond2DateString(int v)
Convert the seconds in string.
int nbh = v / 3600;
int nbm = (v % 3600) / 60;
int nbs = (v % 3600) % 60;
return String.format("%02d:%02d:%02d ", nbh, nbm, nbs);
intsecondsBetween(String from, String to, String format)
seconds Between
SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.UK);
Calendar calendar = Calendar.getInstance(Locale.UK);
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.setMinimalDaysInFirstWeek(4);
Date date1 = null;
Date date2 = null;
try {
    date1 = formatter.parse(from);
...
StringsecondsToDHMSString(double seconds)
seconds To DHMS String
if (seconds < 60) {
    return doubleToString(seconds, 2, 2) + 's';
long secs = (int) (seconds);
long mins = secs / 60;
long hours = mins / 60;
long days = hours / 24;
secs %= 60;
...
StringsecondstoHM(long sec)
Converti une valeur en secondes sous la forme HH:MM
StringBuffer sb = new StringBuffer();
int hrs = getHoursInSec(sec);
if (hrs < 10) {
    sb.append(0);
sb.append(hrs);
sb.append(":"); 
int min = Math.round(getMinutesInSecWOHours(sec));
...
StringsecondsToHumanDate(long seconds)
seconds To Human Date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(CURRENT_TIME_ZONE);
Date t = new Date();
t.setTime(seconds * 1000);
return sdf.format(t);
StringsecondsToString(long seconds)
seconds To String
TimeUnit[] units = TimeUnit.values();
StringBuilder builder = new StringBuilder();
boolean negative = false;
if (seconds < 0) {
    negative = true;
    seconds *= -1;
for (int i = TimeUnit.DAYS.ordinal(); i >= TimeUnit.SECONDS.ordinal(); i--) {
...
StringsecondsToStringFormat(long seconds)
seconds To String Format
long aux = seconds;
int sec = (int) aux % 60;
aux = aux / 60;
int min = (int) aux % 60;
aux = aux / 60;
String res;
if (sec < 10)
    res = ":0" + sec;
...
StringsecondsToTime(double seconds)
seconds To Time
String result;
int minutes = (int) (seconds / 60);
seconds = seconds % 60;
result = new DecimalFormat("#.###").format(seconds) + "s";
if (minutes == 0) {
    return result;
int hours = minutes / 60;
...