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

(2 pack) Dataproducts R5110 IBM 1299845 Compatible Typewriter Ribbon Sealed OEM
$8.99
(2 pack) Dataproducts R5110 IBM 1299845 Compatible Typewriter Ribbon Sealed OEM pictureIBM 1337765 Lift-Off CorrectionTape - Genuine OEM for IBM Wheelwriter
$9.99
IBM 1337765 Lift-Off CorrectionTape - Genuine OEM for IBM Wheelwriter  pictureIBM OEM DPES-31080 DPES31080 Drive Disk 1080MB
$160.3
IBM OEM DPES-31080 DPES31080 Drive Disk 1080MB pictureIBM Lenovo THINKPAD LAPTOP AC POWER ADAPTER 20V 3.2.5A OEM 92P1156 42T5282
$11.0
IBM Lenovo THINKPAD LAPTOP AC POWER ADAPTER 20V 3.2.5A OEM 92P1156 42T5282 pictureIBM #4 Y Cable Genuine OEM Long POS Cash Register 4A to 4B 10N1002 J96367
$24.99
IBM #4 Y Cable Genuine OEM Long POS Cash Register 4A to 4B 10N1002 J96367 picture






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