Convert a Date to a String using DateFormat#format
method:
String pattern = "MM/dd/yyyy HH:mm:ss"; // Create an instance of SimpleDateFormat used for formatting // the string representation of date according to the chosen pattern DateFormat df = new SimpleDateFormat(pattern); // Get the today date using Calendar object. Date today = Calendar.getInstance().getTime(); // Using DateFormat format method we can create a string // representation of a date with the defined format. String todayAsString = df.format(today); // Print the result! System.out.println("Today is: " + todayAsString);
From http://www.kodejava.org/examples/86.html
Related Posts:
- Change date format in a Java string
- Java string to date conversion
- How to compare dates in Java?
- LocalDate to java.util.Date and vice versa simplest conversion?
- Double decimal formatting in Java
- How to get today’s Date?
- How to convert currentTimeMillis to a date in Java?
- Adding days to a date in Java
- How to convert an Instant to a date format?
- Sort ArrayList of custom Objects by property
- Set Date in a single line
- How to determine day of week by passing specific date?
- How to convert a date to milliseconds
- Get integer value of the current year in Java
- How to convert java.util.Date to java.sql.Date?
- Java 8 Iterable.forEach() vs foreach loop
- How to round a number to n decimal places in Java
- Error unable to access jarfile C:\Jar
- In laymans terms, what does ‘static’ mean in Java? [duplicate]
- Sort an array in Java
- Java String Split by “|”
- Could not reserve enough space for object heap
- How can I use pointers in Java?
- JavaFX – Exception in Application start method?
- Is there a stopwatch in Java?
- com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
- Print ArrayList
- Unsupported major.minor version 52.0 [duplicate]
- What is a StringIndexOutOfBoundsException? How can I fix it?
- Non-static variable cannot be referenced from a static context
- How to convert any Object to String?
- How do I copy an object in Java?
- Unfortunately MyApp has stopped. How can I solve this?
- What is the significance of load factor in HashMap?
- Which HTML Parser is the best?
- Returning Arrays in Java
- java.lang.ClassCastException
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘MyController’:
- Can I multiply strings in Java to repeat sequences?
- Why do I get an UnsupportedOperationException when trying to remove an element from a List?
- java.util.NoSuchElementException: No line found
- How to check whether a int is not null or empty?
- How to parse JSON in Java
- Declaring an unsigned int in Java
- Converting Hexadecimal String to Decimal Integer
- What is a Question Mark “?” and Colon “:” Operator Used for?
- How to remove single character from a String
- org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect’ not set
- Is there a concurrent List in Java’s JDK?
- Uri not Absolute exception getting while calling Restful Webservice
- Very Basic Java
- SQLRecoverableException: I/O Exception: Connection reset
- What exactly is a Maven Snapshot and why do we need it?
- How to check if my string is equal to null?
- what is Ljava.lang.String;@
- “Could not find Java SE Runtime Environment.” after installing Java
- How can I create an utility class?
- difference between ‘static int’ and ‘int’ in java
- How to use PrintWriter and File classes in Java?
- Error message “unreported exception java.io.IOException; must be caught or declared to be thrown”
- cannot make a static reference to the non-static field
- Double cannot be dereferenced?
- Encrypt Password in Configuration Files?
- how to do a system pause in java for debugging?
- Immutable class?
- Is spring default scope singleton or not?
- Java Reflection – Object is not an instance of declaring class
- What does “AL lib: alc_cleanup: 1 device not closed” mean?
- Java Enum return Int
- Java, Simplified check if int array contains int
- Converting a string to an integer on Android
- What is the difference between JSF, Servlet and JSP?
- Get only part of an Array in Java?
- How to Get JSON Array Within JSON Object?
- What is a class constant?
- How to represent a fix number of repeats in regular expression?
- How to import a jar in Eclipse
- What is method hiding in Java? Even the JavaDoc explanation is confusing
- Error: class X is public should be declared in a file named X.java
- Resolving File paths – ‘File not found’ error in Eclipse
- Simple Coin Toss using random class in Java. The do while loop doesn’t seem to generate random results
- Why I am getting DefaultHttpClient is deprecated?
- When should you use multithreading? And would multi threading be beneficial if the different threads execute mutually independent tasks?
- How to Convert Int to Unsigned Byte and Back
- Suggestions needed: Effective Java to C source code converter
- Downloading a file from spring controllers
- Java Error Exception in thread “AWT-EventQueue-0” java.lang.StackOverflowError
- Write a program that reads an unspecified number of integers, determines pos, neg, total, average
- Parsing JSON string in Java
- java attempting to assign weaker access privilege error
- Getting a “no interface expected here” when I try to subclass ServiceConnection [duplicate]
- Java regex email
- Java Iterator on Doubly-linked-list
- Why “no projects found to import”?
- Java Swing setting JPanel Size
- how to use “tab space” while writing in text file
- Change Name of Import in Java, or import two classes with the same name
- set background color: Android
- Class JavaLaunchHelper is implemented in two places
- Changing Date Format on Custom Meta Data w/shortcode call