The below function gives the unixtime for the current time in the device
public static long get_unix_time2(long seconds_since_midnight_gmt,
int day_of_month) {
long m_time = 0;
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, cal.get(Calendar.MONTH));
cal.set(Calendar.YEAR, cal.get(Calendar.YEAR));
cal.set(Calendar.DAY_OF_MONTH, day_of_month);
m_time = cal.getTime().getTime();
//Date current = Calendar.getInstance().getTime();
//Date dateTime = new Date();
//long diffInSeconds = (current.getTime() - dateTime.getTime()) / 1000;
//long min = (diffInSeconds = (diffInSeconds / 60)) >= 60 ? //diffInSeconds % 60
// : diffInSeconds;
// m_time = m_time - (min * -3600 * 1000);
return m_time;
}
How can I change the unixtime so that the time from the device is replaced with "seconds_since_midnight_gmt" value recieved as parameter.
You can set the values of the Calendar
object.
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.set(Calendar.SECOND, (int) seconds_since_midnight_gmt);