The Artima Developer Community
Sponsored Link

Java Answers Forum
Java dates - urgent

5 replies on 1 page. Most recent reply: Nov 6, 2003 2:36 AM by Senthoorkumaran Punniamoorthy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 5 replies on 1 page
Peter Kovac

Posts: 2
Nickname: peto
Registered: Nov, 2003

Java dates - urgent Posted: Nov 3, 2003 11:56 PM
Reply to this message Reply
Advertisement
Hello,

I need urgent help with one thing:
I have date formats in a file in DD.MM.YY
DD-day, MM-month, YY-year
and I need to convert it into the format YYYY-MM-DD or YYYY-DD-MM
(or, it has to be PostgreSQL compatible date format)

Any kind of help is good. Thank you very much.


Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: Java dates - urgent Posted: Nov 4, 2003 12:00 AM
Reply to this message Reply
Try using java.text.SimpleDateFormat

Senthoor

Peter Kovac

Posts: 2
Nickname: peto
Registered: Nov, 2003

Re: Java dates - urgent Posted: Nov 4, 2003 1:06 AM
Reply to this message Reply
yes, but how?

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: Java dates - urgent Posted: Nov 4, 2003 3:46 AM
Reply to this message Reply
After pointing in the right direction if you can't look up in the API and figure it out I didn't want to post the answer itself. but next time atleast I guess you will do some work on your own before asking a question.
/**
 * <p>Copyright: Copyright (c) 2003</p>

 * @author P. Senthoorkumaran
 * @version 1.0
 */
 
import java.text.SimpleDateFormat;
import java.text.*;
public class SimpleDate {
  public SimpleDate() {
  }
 
  public static void main(String args[]) {
    String date = "31.05.03";
    SimpleDateFormat myFormat = new SimpleDateFormat("dd.MM.yy");
    SimpleDateFormat mySecFormat = new SimpleDateFormat("yyyy-MM-dd");
      try {
        java.util.Date tempDate = myFormat.parse(date);
        System.out.println(mySecFormat.format(tempDate));
      }
      catch (ParseException ex) {
      }
  }
}

Birendar S Waldiya

Posts: 21
Nickname: ebiren
Registered: Nov, 2003

Re: Java dates - urgent Posted: Nov 5, 2003 9:44 PM
Reply to this message Reply
This too:--

public class ChangeDateFormat
{
public static void main(String[] args)
{

java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat ("MM-dd-yyyy");

java.util.Date currentTime_1 = new java.util.Date();

String dateString = formatter.format(currentTime_1);
System.out.println(dateString);
}
}

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: Java dates - urgent Posted: Nov 6, 2003 2:36 AM
Reply to this message Reply
Hello Ebiren,

I think you have missed one of the requirement in the original post which goes as

> I have date formats in a file in DD.MM.YY
> DD-day, MM-month, YY-year
> and I need to convert it into the format YYYY-MM-DD or
> YYYY-DD-MM

But in your case you seems to generate your own date??

Flat View: This topic has 5 replies on 1 page
Topic: Lock Screen Previous Topic   Next Topic Topic: Date Data Type Field

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use