Search code examples
androidstringdatetimeandroid-graphview

Converting date and time back to millis


I want to plot a graph using graphView , value vs Time. I have value as integer but I have strings for date and time. So, to plot the graph I should be having both values and (date and time) in integral format. So, what should I do to plot the graph . Is there any best method for solving this?


Solution

  • Use Calendar:

        Calendar cal = Calendar.getInstance();
    
        int yearX = 1980;
        cal.set(Calendar.YEAR, yearX);
        int monthX = 5;
        cal.set(Calendar.MONTH, monthX);
        int dayX = 15;
        cal.set(Calendar.DAY_OF_MONTH, dayX);
        int hourX = 1;
        cal.set(Calendar.HOUR_OF_DAY, hourX);
        int minX = 25;
        cal.set(Calendar.MINUTE, minX);
        int secX = 55;
        cal.set(Calendar.SECOND, secX);
        int milX = 15;
        cal.set(Calendar.MILLISECOND, milX);
    
        long millis = cal.getTimeInMillis();