BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 09-14-2010, 04:26 PM   #1
romah
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
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
romah
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
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
Dougsg38p
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
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



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


APPLE 630-0895-B  VRAM 128K X 8 BOARD CARD VINTAGE picture

APPLE 630-0895-B VRAM 128K X 8 BOARD CARD VINTAGE

$74.77



APPLE 820-0522-A 630-0895-B LITE VRAM 128K X 8 BOARD  picture

APPLE 820-0522-A 630-0895-B LITE VRAM 128K X 8 BOARD

$149.99



128K RAM - APPLE - ORIGINAL APPLE prototype BOARD picture

128K RAM - APPLE - ORIGINAL APPLE prototype BOARD

$408.75







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