String time = (songLength/60)+":"+ (songLength%60);
if (songLength%60 < 10)
time = (songLength/60)+":"+ "0" + (songLength%60);
return time;
i got it all right there, thanks for the help
String DATE_FORMAT = "dd/MM/yyyy HH:mm:ss"; //for example
// TODO Auto-generated method stub
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.SECOND, calendar.get(Calendar.MINUTE)+500);
System.out.println(calendar.get(Calendar.MINUTE));
Date customDate = calendar.getTime();
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
//System.out.println(customDate);//you can format this date
System.out.println(sdf.format(customDate));
> >
>
> String time = (songLength/60)+":"+
> (songLength%60);
>if (songLength%60 < 10)
> time = (songLength/60)+":"+ "0" +
> (songLength%60);
>return time;
> got it all right there, thanks for the help
This can be simplified using a Java 1.5 feature
String formattedMinutes = String.format("%d:%02d", minutes / 60, minutes % 60);
> String time = (songLength/60)+":"+(songLength%60);
>if (songLength%60 < 10)
> time = (songLength/60)+":"+ "0" +(songLength%60);
>return time;
>
> got it all right there, thanks for the help
You can make that a one-liner:String format(int seconds) {
return (seconds/60)+((seconds%60)<10?":0":":")+(seconds%60);
}
Message was edited by:
prometheuzz
Or beter, like sabre150 did!
> String DATE_FORMAT = "dd/MM/yyyy HH:mm:ss"; //for
> example
>
> // TODO Auto-generated method stub
> Calendar calendar = Calendar.getInstance();
>
> calendar.set(Calendar.SECOND,
> D, calendar.get(Calendar.MINUTE)+500);
> System.out.println(calendar.get(Calendar.MINUTE));
> Date customDate = calendar.getTime();
>
> SimpleDateFormat sdf = new
> ew SimpleDateFormat(DATE_FORMAT);
> //System.out.println(customDate);//you can format
> this date
> System.out.println(sdf.format(customDate));
I have a real problem with this approach. A number of minutes are not a date. They only become a date when relative to some point in time and your approach uses 1st Jan 1970. Since this approach uses SimpleDateFormat which have a built in time zone, the approach will fail for time differences that involve daylight saving and Leap years.