BlackBerry Forums Support Community
              

Closed Thread
 
LinkBack Thread Tools
Old 09-14-2010, 04:26 PM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Convert String to Date/Time

Please Login to Remove!

I am trying to get time(long type) from the given datetime string.
While searching, I found these two ways but both are not working for me.

Code:
//import net.rim.device.api.i18n.DateFormat;
//import java.text.DateFormat;
String dateString="9/14/2010 3:59:27 PM";
DateFormat df = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss aa"); 
Date date=df.parse(dateString);
long time=date.getTime();
In above code, the problem is in df.parse(dateString);
There is no parse method for net.rim.device.api.i18n.DateFormat.
and when I tried to import "java.text.DateFormat", it says "cannot be resolved", i.e., package not found.



Code:
String dateString="9/14/2010 3:59:27 PM";
Date date= new Date(HttpDateParser.parse(dateString));
long time=date.getTime();
In this code, the second line date will result 0 millisecond.

What will be the solution?
Offline  
Old 09-16-2010, 11:23 AM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I found that it works fine if the dateString is changed to the format "yyyy-MM-dd hh:mm:ss".

Code:
String dateString="2009-07-31 07:59:17";
Date formatter = new Date(HttpDateParser.parse(dateString));
long time=formatter.getTime();
But our web service, which is not modifiable, returns the format "MM/dd/yyyy hh:mm:ss aa". Is there any work around or solution?

One more thing is that HttpDateParser.parse() is only accessible by signed applications. Although it won't be the problem for my application, again if there is any other way to solve it, please post the solution. Thanks !

Last edited by romah : 09-16-2010 at 11:30 AM.
Offline  
Old 09-16-2010, 01:51 PM   #3 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

Since the date format is fixed, why don't you just write your own parser? You'll extract the various date elements, place them in a Calendar instance, and then get the Date() from the calendar.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

MOTOROLA/SYMBOL 2A CBA-U09-C15ZAR MOTOROLA/SYMBOL DC - IA 15FT CABLE USB COIL...
$74.91
MOTOROLA/SYMBOL 2A CBA-U09-C15ZAR MOTOROLA/SYMBOL DC - IA 15FT CABLE USB COIL... pictureDBI SALA 1500061 Python Safety Hard Hat Coil Tether (10 Pack) 2 lb
$78.99
DBI SALA 1500061 Python Safety Hard Hat Coil Tether (10 Pack) 2 lb pictureNEW Square D Heavy Duty Power Relay CO-16 Class 8501 Contact Coil Series B
$14.99
NEW Square D Heavy Duty Power Relay CO-16 Class 8501 Contact Coil Series B pictureAllen-Bradley 100-C09D10 Contactor, IEC, 9A, 3P, 120V Coil
$34.99
Allen-Bradley 100-C09D10 Contactor, IEC, 9A, 3P, 120V Coil pictureBlack Metal Coil Spring Letter Or Napkin Holder With Cup Holder
$1.99
Black Metal Coil Spring Letter Or Napkin Holder With Cup Holder picture






Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.