Menu

On a Java Date processing

smallfish
2009-12-04
2012-09-26
  • smallfish

    smallfish - 2009-12-04

    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;

    public class DateTest {

    /
    @param args
    /
    Date date = new Date();
    static Calendar calendar = Calendar.getInstance();
    public void todays(){
    calendar.set(2009, 12, 16, 14, 20, 30);
    date = calendar.getTime();
    DateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    String s = formatDate.format(date);
    System.out.println(s);
    }
    public static void main(String args) {
    DateTest dt = new DateTest();
    dt.todays();
    }
    }
    This code running result 2009-12-16 why not 14:20:30
    But 2010-01-16:02:20:30
    Consult the master where there are problems?

     
  • cpns

    cpns - 2009-12-04

    You appear to be on the wrong forum, Dev-C++ does not support Java; the clue
    is in the name. Moreover you are not going to get much help unless you get the
    code mark-up right!


    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;

    public class DateTest {

    /
    @param args
    /
    Date date = new Date();
    static Calendar calendar = Calendar.getInstance();
    public void todays(){
    calendar.set(2009, 12, 16, 14, 20, 30);
    date = calendar.getTime();
    DateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    String s = formatDate.format(date);
    System.out.println(s);
    }
    public static void main(String args) {
    DateTest dt = new DateTest();
    dt.todays();
    }
    }

    This code running result 2009-12-16 why not 14:20:30
    But 2010-01-16:02:20:30
    Consult the master where there are problems?


     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.