• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Date Formate Problem

 
Ranch Hand
Posts: 151
MyEclipse IDE Python Java
  • 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
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the class java.text.DateFormat.
 
Sheriff
Posts: 21997
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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
MyEclipse IDE Python Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


i tried this but not reached on solution
 
Rob Spoor
Sheriff
Posts: 21997
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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
MyEclipse IDE Python Java
  • 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
 
Ranch Hand
Posts: 93
IntelliJ IDE VI Editor Java
  • 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
MyEclipse IDE Python Java
  • 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
 
Marshal
Posts: 25812
69
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
MyEclipse IDE Python Java
  • 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: 21997
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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.
 
    Bookmark Topic Watch Topic
  • New Topic