This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Convert date in difference format

 
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a date as String in dd/mm/yyyy (07/12/2005) format.

I want to convert it into dd-MMM-yy(07-DEC-05) format.

How to do this?

Are there any free libraries for that?
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Are there any free libraries for that?



Y do u need a seperate utility class for this.

Use SimpleDateFormat and specify the format u want the u get the result.

For examples see here
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is sample code for ur query.

package mypackage;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Test
{
public Test()
{

String dateString = new String("07/12/2005");
java.util.Date dtDate = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yy");
SimpleDateFormat sdfAct = new SimpleDateFormat("dd/mm/yyyy");
try
{
dtDate = sdfAct.parse(dateString);
System.out.println("Date After parsing in required format:"+(sdf.format(dtDate)));
}
catch (ParseException e)
{
System.out.println("Unable to parse the date string");
e.printStackTrace();
}
}

/**
*
* @param args
*/
public static void main(String[] args)
{
Test test = new Test();
}
}
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic