I'm getting a NumberFormatException while executing the below statements.
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day_of_month = 15;
long m_time = Long.parseLong((month + 1) + "/" + day_of_month + "/" + year);
and
long m_time = Long.parseLong(String.valueOf((month + 1) + "/" + day_of_month + "/" + year));
The reason for the NumberFormatException is cause you are trying to parseLong a String that is not a valid long representation: "2/15/2015"
To parse the date string you've come up with correctly use this code:
"2/15/2015" type of string cannot be parsed by the
Long.parseLong()
method. Use SimpleDateFormat.You're attempting to parseLong on a concatenated string with a lot of non-numeric characters.
If you're trying to obtain the
Long
value of a given date:If you're looking to format a
Date
object to aString
: