• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 83
  • Last Modified:

Converting string to long

Dear all,

I'm reading data from an excel file.  One of the columns is Time, containing data in this format "00:30:00".  The excel cell type is TIME.

I tried to parse the string (details[0]) to a long, its returning a number format exception.
long step = Long.parseLong(details[0]);

How to go about this?  Thanks
0
AndyC1000
Asked:
AndyC1000
1 Solution
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Depending on what you actually want as the result (ie. milliseconds, seconds, minutes, etc) try one of the below...

long milliseconds = new SimpleDateFormat("HH:mm:ss").parse(details[0]).getTime();
long seconds = new SimpleDateFormat("HH:mm:ss").parse(details[0]).getTime() / 1000;
long minutes = new SimpleDateFormat("HH:mm:ss").parse(details[0]).getTime() / 60000;

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Tackle projects and never again get stuck behind a technical roadblock.
Join Now