• Post Reply Bookmark Topic Watch Topic
  • New Topic

Date Formate Problem  RSS feed

 
akhter wahab
Ranch Hand
Posts: 151
Java MyEclipse IDE Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello i wrote a program that accept date formate like DD/MM/YYYY in a String i have to seprate the DD ,MM,YYYY from this i was doing this by using substring method now problem is when someone give him date like D/MM/YYY or DD/M/YYYY it fails please suggest me how i can seprate these things correctly
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the class java.text.DateFormat.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Parse the String into a Date (java.text.DateFormat)
Convert the Date into a Calendar (java.util.Calendar)
Get the data from the Calendar.
 
akhter wahab
Ranch Hand
Posts: 151
Java MyEclipse IDE Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


i tried this but not reached on solution
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you read my post (again?) you should be able to do it. You already found a very good DateFormat subclass (SimpleDateFormat). Find the right pattern to create an instance. Use the parse method (I have given you that word for free before).

Using the other class from my post you should now be able to finish this.
 
akhter wahab
Ranch Hand
Posts: 151
Java MyEclipse IDE Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:If you read my post (again?) you should be able to do it. You already found a very good DateFormat subclass (SimpleDateFormat). Find the right pattern to create an instance. Use the parse method (I have given you that word for free before).

Using the other class from my post you should now be able to finish this.



but its giving me wrong output of date
 
Eduardo Yañez Parareda
Ranch Hand
Posts: 93
IntelliJ IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First take a look at javadoc of SimpleDateFormat

It gives you an example to do what you need. Also I'll give you a clue... mm/dd/yyyy ... 'mm' no way!
 
akhter wahab
Ranch Hand
Posts: 151
Java MyEclipse IDE Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eduardo Yañez Parareda wrote:First take a look at javadoc of SimpleDateFormat

It gives you an example to do what you need. Also I'll give you a clue... mm/dd/yyyy ... 'mm' no way!


i solve my problem using regex but not reached at any solution using java
 
Paul Clapham
Sheriff
Posts: 22829
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
akhter wahab wrote:hello i wrote a program that accept date formate like DD/MM/YYYY in a String


akhter wahab wrote:but its giving me wrong output of date


Was there some particular reason you chose the format "mm/dd/yyyy" to parse a date formatted like "dd/mm/yyyy"?
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to use the quote:

Some people, when confronted with a problem, think "I know, I’ll use regular expressions." Now they have two problems. --"Jamie Zawinski
 
akhter wahab
Ranch Hand
Posts: 151
Java MyEclipse IDE Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouter Oet wrote:Just to use the quote:

Some people, when confronted with a problem, think "I know, I’ll use regular expressions." Now they have two problems. --"Jamie Zawinski


i am not good is Java enough even these hints not make me able to solve this problem using java thats why i use regex
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need to be good at Java to read the documentation and various hints and concrete code we have given you. This way you're writing code that produces the wanted results but in a manner that is unwanted.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
akhter wahab wrote:
Eduardo Yañez Parareda wrote:First take a look at javadoc of SimpleDateFormat

It gives you an example to do what you need. Also I'll give you a clue... mm/dd/yyyy ... 'mm' no way!


i solve my problem using regex but not reached at any solution using java

Then you need to re-read the SimpleDateFormat Javadoc page. Hint: the characters in the pattern are case sensitive, and mm does not mean month.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!