From a formatted time string to a long (just the time) - Android java.util

Android examples for java.util:Time

Description

From a formatted time string to a long (just the time)

Demo Code


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.Random;
import android.graphics.Color;

public class Main{
    /**//w ww  .ja  va 2  s  .c  o m
     * From a formatted time string to a long (just the time)
     * 
     * @param timeString
     * @return time in long
     * @throws ParseException
     */
    public static long timeBackToLong(String timeString)
            throws ParseException {
        SimpleDateFormat dateFormat;
        dateFormat = new SimpleDateFormat(Globals.TIME_FORMAT, Locale.US);

        System.out.println("df " + dateFormat.parse(timeString));
        System.out.println("df " + dateFormat.parse(timeString).getTime());

        return dateFormat.parse(timeString).getTime();
    }
}

Related Tutorials