How to get the current date time values using Calendar in Java

1 Answer

0 votes
package javaapplication1;

import java.util.Calendar;

public class JavaApplication1 {

    public static void main(String[] args) {

        Calendar now = Calendar.getInstance();
        
        System.out.println("Today: " + (now.get(Calendar.MONTH) + 1) + "-"
                            + now.get(Calendar.DATE)
                            + "-"
                            + now.get(Calendar.YEAR)
                            + "   "
                            + now.get(Calendar.HOUR_OF_DAY)
                            + ":"
                            + now.get(Calendar.MINUTE)
                            + ":"
                            + now.get(Calendar.SECOND)
                            + "."
                            + now.get(Calendar.MILLISECOND)
                          );
    }
}

/*

run:

Today: 10-19-2016   18:25:57.752

*/

 



answered Oct 19, 2016 by avibootz

Related questions

1 answer 185 views
1 answer 187 views
1 answer 199 views
1 answer 244 views
1 answer 192 views
1 answer 173 views
1 answer 177 views
...