473,327 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

convertion of format not working

14
Hi Friends,

I have one due_date variable as string we are declaring . we get the value from service as "2014-02-17T00:00:00:0" LIKE
but, i want the format like '17-FEB-14' as string why because i need to pass this value as string to another method.
how can i acheive it.

i wrote like this.

Expand|Select|Wrap|Line Numbers
  1. StringTokenizer st = new StringTokenizer(due_date, "T");
  2.       String str = st.nextToken();
  3.       SimpleDateFormat formatter5=new SimpleDateFormat("dd-MMM-yyyy");
  4.        due_date2 = formatter5.format(str);

but i got error here, due_date2 = formatter5.format(str);
as can not pass object to date like
Apr 14 '14 #1
3 1207
chaarmann
785 Expert 512MB
You are trying to parse "2014-02-17" with "dd-MMM-yyyy". Of course that is not possible! (Just notice that "17-Feb-2014" would be successfully parsed!) Just read about SimpleDateFormat and the meaning of "dd", "MMM" and "yyyy" and change it so it will parse correctly.
Second step: You don't need a String tokenizer. Just giving the right format string is enough.

To make it clear:
Don't be confused with original format and desired format.
First parse the original string (original format) into a date object
Second print the date object in desired format.
Apr 14 '14 #2
santhu1
14
Hi chaarmann,

thanks for reply i have done some changes it is working fine now.

Expand|Select|Wrap|Line Numbers
  1. StringTokenizer st = new StringTokenizer(due_date, "T");
  2.     String str = st.nextToken();
  3.         DateFormat fromFormat = new SimpleDateFormat("yyyy-MM-dd");
  4.  
  5.     DateFormat toFormat = new SimpleDateFormat("dd-MMM-yy");
  6.  
  7.     Date date = fromFormat.parse(str);
  8.     due_date2=toFormat.format(date);
Apr 14 '14 #3
chaarmann
785 Expert 512MB
Nearly perfect. That means, it works, but does unnecessary stuff.
Just remove the StringTokenizer. That means, delete line 1 and 2.
In line 5, use the date-string directly, that means change it to "Date date = fromFormat.parse(due_date);"
Please notice that the parser will ignore all characters given after the parse pattern. That means in your case it will ignore everything after the day "dd", so you do not need to separate the time from the date before by splitting the string.
Apr 16 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Petr Studenovsky | last post by:
Hello I made small GUI test program in Visual Basic NET for SQL communication. I need some help with these problems. problem 1) If I change some settings in datagrid from properties window...
6
by: Chiller | last post by:
I'm in the process of writing a class that performs functions on a Distance object. The object is created by entering details as "Distance a (5, km)" or "Distance b (3, cm)" etc. I wish to write...
0
by: Tony_E | last post by:
Hello I am trying to export a Crystal Report (8.5) out of an ACCESS (2002) function. crxReport.ExportOptions.FormatType = crEFTExcel80 FlPth = "C:\Reports\CrystalReport" & ".xls"...
0
by: McKoy | last post by:
Hi, I'm translating some code from C++ to C#, but I don't know how to change the code below to get it working under C# ...., I've tried explicity convertion, but without any results :( Please...
4
by: juli | last post by:
Good afternoon! I have an error while trying to convert to DateTime ,here is the code and the error: ArrayList al = new ArrayList(); temp_str=Line.Split(' '); al.Add(temp_str); //...
7
by: Filips Benoit | last post by:
Dear all, Tables: COMPANY: COM_ID, COM_NAME, ..... PROPERTY: PRP_ID, PRP_NAME, PRP_DATATYPE_ID, PRP_DEFAULT_VALUE ( nvarchar) COMPANY_PROPERTY: CPROP_COM_ID, CPROP_PRP_ID, CPROP_VALUE...
8
by: Thunder | last post by:
Hi All, I'm using VB.Net 2005. I have for years used Format to format strings and dates, etc... Now when I try to use Format I get the following error? "'Format' is a type and can not be used...
1
by: jagalla | last post by:
Hi, Am Srinivas Jagalla, am getting error Date format. Whatever the format I provided in Local that is comming properly. when I uploaded in live there it isn't comming same format. ex: am...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.