Java Date.....................?
-
this might sound a little silly.. how do you take date input in java list of my attempts 1.i used the Calender class Calendar c= Calendar.getInstance(); then i took individual inputs Calendar.YEAR.....MONTH DATE despite taking individual inputs...(except for DATE) i get wrong values when i print the values to the console is the some way in which i can take the complete input from the user eg 21/02/2000 no matter what i try ... i just cant seem to print the values i took as input to the console... this is what i tried... //////////////////////////////////////… System.out.println("Enter Year"); d.set(Calendar.YEAR, Integer.parseInt(buf.readLine())); System.out.println("Enter Month"); d.set(Calendar.MONTH, Integer.parseInt(buf.readLine())); System.out.println("Enter Date"); d.set(Calendar.DATE, Integer.parseInt(buf.readLine())); //////////////////////////////////////… values i gave as input year=2000, month=02,date =21 output year=5, month=3,date =1 ------>strange!! or any technique to take a date input would do.....
-
Answer:
public static void main( String[] args) { int year, month, date; Scanner console = new Scanner( System.in); System.out.print( "Enter Year: "); year = console.nextInt(); System.out.print( "Enter Month: "); month = console.nextInt(); System.out.print( "Enter Day: "); date = console.nextInt(); Calendar calendar = Calendar.getInstance(); calendar.set( year, month-1, date); DateFormat dateFormat = new SimpleDateFormat( "yyyy/MM/dd HH:mm:ss aaa"); System.out.println( dateFormat.format( calendar.getTime())); } good luck don't forget to choose best answer
Cherry at Yahoo! Answers Visit the source
Related Q & A:
- How to Convert Json date string to more readable date format?Best solution by SharePoint
- How to store global date time and convert it to local date time?Best solution by Stack Overflow
- How to Implement Gateway Service something similar to Oracle API gateway Using Java and Java based Open Source frameworks only?Best solution by Quora
- How do we convert past date into future date?Best solution by Stack Overflow
- Difference between Java 2 and Java 6?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.