Engageya

Tuesday, July 21, 2009

Where is maven central repository?

Where is maven central repository?

Posted: 20 Jul 2009 04:41 AM PDT

undefined

Maven central repository is located at

http://repo1.maven.org/maven2/

Java – How to get current date time – date() ,calender() ,SimpleDateFormat()

Posted: 20 Jul 2009 04:39 AM PDT


We can get current date time in java with three classes – SimpleDateFormat(), Date() or Calender().

Here i demonstrate two examples to show how to get current date time in java.

1) Date() + SimpleDateFormat()

DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
System.out.println(dateFormat.format(date));

2) Calender() + SimpleDateFormat()

DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
System.out.println(dateFormat.format(cal.getTime()));

P.S Please access java documentation here to understand more date time format in SimpleDateFormat
http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html

Here is full source code.


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package com.mkyong;

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


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

DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
//get current date time with Date()
Date date = new Date();
System.out.println(dateFormat.format(date));

//get current date time with Calendar()
Calendar cal = Calendar.getInstance();
System.out.println(dateFormat.format(cal.getTime()));

}
}

No comments:

Linkwithin

Related Posts Plugin for WordPress, Blogger...