answersLogoWhite

0


Best Answer

When you create a SimpleDateFormat object, you specify a pattern String. The contents of the pattern String determine the format of the date and time. For a full description of the pattern's syntax, see the tables in Date Format Pattern Syntax.

The following code formats a date and time according to the pattern String passed to the SimpleDateFormat constructor. The String returned by the format method contains the formatted date and time that are to be displayed. Date today;

String output;

SimpleDateFormat formatter;

formatter = new SimpleDateFormat(pattern, currentLocale);

today = new Date();

output = formatter.format(today);

System.out.println(pattern + " " + output);

The following table shows the output generated by the previous code example when the U.S. Locale is specified:

Customized Date and Time FormatsPatternOutputdd.MM.yy30.06.09yyyy.MM.dd G 'at' hh:mm:ss z2009.06.30 AD at 08:29:36 PDTEEE, MMM d, ''yyTue, Jun 30, '09h:mm a8:29 PMH:mm8:29H:mm:ss:SSS8:28:36:249K:mm a,z8:29 AM,PDTyyyy.MMMMM.dd GGG hh:mm aaa2009.June.30 AD 08:29 AM

source:http://java.sun.com/docs/books/tutorial/i18n/format/simpleDateFormat.html

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you convert a java.util.Date to java.lang.String in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Explanation of import javautilDate?

The import keyword in Java is used to tell the Java compiler where to find different classes and packages.java.util.Date is the location of the Date class: Date is a member of the util package, which is a member of the java package.


Can you convert date into words in java?

yes


How do you convert string to int in Java?

One can convert a string variable to an int variable in Java using the parse integer command. The syntax is int foo = Integer.parseInt("1234"). This line will convert the string in the parenthesis into an integer.


How do you convert java data to SQL data?

kill urself


Which is the best way to convert numbers in string under java?

All of the Java number classes have a parse[type] method, like parseInt() in Integer or parseDouble() in Double that convert Strings to primitive numbers. String s = getInput(); int var = Integer.parseInt(s);


How can someone convert string to int in Java?

To convert string to int in Java, the easiest way is to simply use the method Integer.parseInt(). For more information how to do this, refer to the integer class documents.


How do you convert numbers into words using java?

Using toString() method


Any algo is used for converting class file to java source file?

You need a decompiler to convert class files to java source files. JAD is a Java Decompiler that can do it for you.


What is the code required to convert an integer variable to a string variable in Java?

There are several different methods to convert an integer variable to a string variable in Java. For example, one can use the following code to convert an integer variable to a string variable: Integer.toString(number)


How can you convert byte to string in java?

To convert byte to String in java use the String(bytes, UTF-8); //example for one encoding type. You must know the special encoding that contains a variety of characters.


Java program to convert lowercase to uppercase?

You can use the toUpperCase() method on a String to convert any String to all uppercase.


How to convert English words to Telugu words using java coding?

efef