Back to project page Weather.
The source code is released under:
Apache License
If you think the Android project Weather listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.volitic.weather; /* w w w .j a v a 2 s . co m*/ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.concurrent.TimeUnit; public class Time { public static String secondsToTime( float seconds, int adjustment, boolean use_seconds ){ if(adjustment > 12 || adjustment < -12){ adjustment = 0; } seconds = seconds + adjustment * 3600; //timezone conversion; int SECONDS_IN_A_DAY = 60*60*24; //clamp to a single day if(seconds < 0 ){ seconds = SECONDS_IN_A_DAY + seconds; } else if ( seconds > SECONDS_IN_A_DAY ){ seconds = seconds - SECONDS_IN_A_DAY; } int hours = (int)seconds / 3600; seconds = seconds % 3600; int minutes = (int)seconds / 60; seconds = seconds % 60; String result = String.format("%02d", hours) + ":" + String.format("%02d", minutes); if(use_seconds){ result += ":" + Integer.toString((int)seconds); } return result; } public static String secondsToTime(float seconds, int adjustment ){ return secondsToTime(seconds, adjustment, false); } public static long dateToSeconds(String date_string, boolean only_time ){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz"); Date date; try{ date = sdf.parse(date_string+"UTC"); }catch (ParseException e ){ return 0; } if(only_time){ return TimeUnit.MILLISECONDS.toSeconds(date.getTime()) % TimeUnit.DAYS.toSeconds(1); } return TimeUnit.MILLISECONDS.toSeconds( date.getTime()); } }