Java programming at HelpWithAssignment.com (basic_date_formatting)

951 views
920 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
951
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Java programming at HelpWithAssignment.com (basic_date_formatting)

  1. 1. Java Programming at HelpWithAssignment.com (Basic Date Formatting)<br /> www.HelpWithAssignment.com<br />
  2. 2. Java is one of the most popular Programming languages in use today in Application software and Web Applications. <br />It is a general-purpose, concurrent, class based and object oriented language that is specifically designed to have implementation dependencies as possible. <br />Basic Date Formatting<br /> www.HelpWithAssignment.com<br />
  3. 3. Basic Date Formatting<br /> Let us see an example for Basic Date Formatting.<br /> package com.ack.j2se.date;<br /> import java.text.DateFormat;<br /> import java.text.SimpleDateFormat;<br /> import java.util.Calendar;<br /> import java.util.Date;<br />Contd<br />Basic Date Formatting<br /> www.HelpWithAssignment.com<br />
  4. 4. public class BasicDateFormatting {<br /> public static void main( String[] args ) throws Exception {<br /> // get today's date<br /> Date today = Calendar.getInstance().getTime();<br /> // create a short version date formatter<br />DateFormatshortFormatter<br /> = SimpleDateFormat.getDateInstance( SimpleDateFormat.SHORT );<br />Basic Date Formatting<br /> www.HelpWithAssignment.com<br />
  5. 5. // create a long version date formatter<br />DateFormatlongFormatter<br /> = SimpleDateFormat.getDateInstance( SimpleDateFormat.LONG);<br /> <br /> // create date time formatter, medium for day, long for time<br />DateFormatmediumFormatter<br /> = SimpleDateFormat.getDateTimeInstance( SimpleDateFormat.MEDIUM,<br />SimpleDateFormat.LONG);<br />Basic Date Formatting<br /> www.HelpWithAssignment.com<br />
  6. 6. // use the formatters to output the dates<br />System.out.println( shortFormatter.format( today ) );<br />System.out.println( longFormatter.format( today ) );<br />System.out.println( mediumFormatter.format( today ) );<br />Basic Date Formatting<br /> www.HelpWithAssignment.com<br />
  7. 7. // convert form date -> text, and text -> date<br /> String dateAsText = shortFormatter.format( today );<br />Date textAsDate = shortFormatter.parse( dateAsText );<br />System.out.println( textAsDate );<br />}<br /> }<br />Basic Date Formatting<br /> www.HelpWithAssignment.com<br />
  8. 8. Here in the above coding we can see that the program is used to fetch date. Date formats are of four types, Short, Medium, Long and Full. The above functions are used to call the date and date & time formats as well.<br />Basic Date Formatting<br /> www.HelpWithAssignment.com<br />
  9. 9. // get today's date<br />Date today = Calendar.getInstance().getTime(); initializes the date function. And the following line <br />// create a short version date formatter<br />DateFormatshortFormatter<br />Basic Date Formatting<br /> www.HelpWithAssignment.com<br />
  10. 10. This and the following lines of code are written to include the different date and date time formats. The various date and date time formats are:<br />Basic Date Formatting<br /> www.HelpWithAssignment.com<br />
  11. 11. SHORT is completely numeric, such as 12.13.52 or 3:30pm<br />MEDIUM is longer, such as Jan 12, 1952<br />LONG is longer, such as January 12, 1952 or 3:30:32pm<br />FULL is pretty completely specified, such as Tuesday, April 12, 1952 AD or 3:30:42pm PST.<br />Basic Date Formatting<br /> www.HelpWithAssignment.com<br />
  12. 12. At HelpWithAssignment.com we provide the best Assignment help, Homework help and Online Tutoring in Java and other Programming languages. Our tutors are experts in Java and other Programming Languages like C, C++, C#, ASP.net, JSP.net, QBasic, Perl, Fortran, etc. The list is not exhaustive. <br />HelpWithAssignment.com<br /> www.HelpWithAssignment.com<br />
  13. 13. For more details you can visit our website at http://www.helpwithassignment.com and http://www.helpwithassignment.com/programing-assignment-help<br />HelpWithAssignment.com<br /> www.HelpWithAssignment.com<br />
  14. 14. You can follow us on our blog at http://helpwithassignment.blogspot.com/ and http://helpwithassignment.wordpress.com/<br />Thank You<br />HelpWithAssignment.com<br /> www.HelpWithAssignment.com<br />

×