• Post Reply Bookmark Topic Watch Topic
  • New Topic

Number format exception while parsing the date to long  RSS feed

 
sn omen
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm getting a NumberFormatException while executing the below statements.



and
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This isn't a long. It has slashes in it. To convert a date to a long, you call:



This converts the calendar to a date and then the date to the number of milliseconds since 1970.
 
sn omen
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So How can I pass this String "01/31/2015" to get the long or milliseconds value?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sn omen wrote:So How can I pass this String "01/31/2015" to get the long or milliseconds value?


Well, you can try using the SimpleDateFormat class? I believe that the latest version of Java also have newer classes that does it, but the SimpleDateFormat should work for your use case.

Henry
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!