• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

import calendar

 
Greenhorn
Posts: 26
Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to input a date, and i want to find out what's the day of that day.
Format : mmddyyy

Example : 10/23/2015
How ?



Then .. ?
 
Sheriff
Posts: 7123
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Depends on the version of Java you're on. If it's version 8, try looking at this:

https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html#of-int-int-int-

You would need to turn your Strings into integers.
 
Marshal
Posts: 76802
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If at all possible, only use the Java8 date classes (or something like Joda Time). They are much better than the older classes. What Knute showed you is an example; you can read a lot more about them in the Java™ Tutorials. You should be able to pass 23:10:15 and get 23rd October 2015. I expect the tutorial will tell you how.

Beware: if you use Scanner#nextLine() things can go horribly wrong if you have previously called its nextXXX methods. If anything nasty happens, start reading here.
 
Saloon Keeper
Posts: 9713
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you using three digits for the year?
 
Campbell Ritchie
Marshal
Posts: 76802
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And why did you write mmddyyy (where m does not mean month) in one place and 10/23/2015 with / / elsewhere?
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this
 
Gabrielle Linkherz
Greenhorn
Posts: 26
Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:Why are you using three digits for the year?



My mistakes. I meant yyy. Thanks
 
Gabrielle Linkherz
Greenhorn
Posts: 26
Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Molayo Decker wrote:Try this



Why your program showing Day of January 1st 1970, not from my input or your example?
 
Gabrielle Linkherz
Greenhorn
Posts: 26
Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:And why did you write mmddyyy (where m does not mean month) in one place and 10/23/2015 with / / elsewhere?



What do you mean? Well, if you're asking for my format, i did mean m : month, y : year, and so on. And when i used date format in excel, the format is month first. So, i think many people used this format, Don't they?
 
Marshal
Posts: 27450
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gabrielle Linkherz wrote:Well, if you're asking for my format, i did mean m : month, y : year, and so on. And when i used date format in excel, the format is month first. So, i think many people used this format, Don't they?



Yes, a lot of people do that. And after they get strange results they post their question on a forum, where people tell them that "m" means "minute" and not "month" as far as DateFormat is concerned. It might also be a good idea for you to check the documentation for SimpleDateFormat to see what's the difference between "MM" and "MMM", and other useful things.
 
Campbell Ritchie
Marshal
Posts: 76802
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gabrielle Linkherz wrote:. . . i did mean m : month, y : year, and so on. And when i used date format in excel, the format is month first. . . .

Paul C has already told you that Java® will not interpret m as month. The month‑day‑year format is usually used in the United #states, but other formats are in common use in other countries.
 
Molayo Decker
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gabrielle,
Check the documentation on SimpleDateFormat http://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html. Have you tried changing the date format to start from month to year?
 
Campbell Ritchie
Marshal
Posts: 76802
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Better suggestion: stop using Calendar and its subclasses. Use LocalDate instead (Java8 only). More details in the Java™ Tutorials.
 
No thanks. We have all the government we need. This tiny ad would like you to leave now:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic