Search code examples
javaandroidtimezonemilliseconds

convert time to millisecond then make a notification manger for this time


I'm trying to convert a time in this format 00:00 to millisecond , but how do I know that the conversion is correct? sample: ||the time for 00:00 in millisecond its>> 1459641652035 || ||the time for 14:20 in millisecond its>> 1459693252035 || this is my code

 Calendar calendar = Calendar.getInstance();
        TimeZone timezone =  TimeZone.getTimeZone("UTC+03:00");

        calendar.setTimeZone(timezone);

        Medicine obj1=new Medicine ();

        Long time[] = new Long[obj1.times.length];



        for (int i = 0; i < obj1.times.length; i++) {
//this loop to get each time (hour and Minute) and convert them to millisecond
            calendar.set(Calendar.HOUR_OF_DAY,Integer.parseInt(obj1.times[i].substring(0,2);
          calendar.set(Calendar.MINUTE,Integer.parseInt(obj1.times[i].substring(3, 5)));
     time[i] = calendar.getTimeInMillis();


        }


        return time;

    }

is it correct?

I also try to do it like this

hour= Integer.parseInt(obj1.times[i].substring(0, 2));
             min=Integer.parseInt(obj1.times[i].substring(3, 5));
             Milli=new Long((hour*60*60*1000)+(min*60*1000));
            time[i]=Milli;

but here I didn't specified the timezone! is this will work?


Solution

  • Your sample is

    ||the time for 00:00 in millisecond its>> 1459641652035 ||

    Clearly, 00:00 should convert to 0 in milliseconds, so the conversion is incorrect.