获取本机IP java

InetAddress.getLocalHost().getHostAddress()

需要:

import java.net.InetAddress;
import java.net.UnknownHostException;

Example:

import java.net.InetAddress;
import java.net.UnknownHostException;
public class GetIPAddressInnerExample {

	/**
	 * @param args
	 * @throws UnknownHostException 
	 */
	public static void main(String[] args) throws UnknownHostException {
		// TODO Auto-generated method stub
		System.out.println(InetAddress.getLocalHost().getHostAddress());
	}
}

Result:

 

@CacheTechShare
 

获取系统时间字符串 java

DateFormat.getDateTimeInstance().format(new Date());

需要:

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

Example:

import java.text.DateFormat;
import java.util.Date;
public class GetCurrentDateTimeExample {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println(DateFormat.getDateTimeInstance().format(new Date()));
	}
}

Result:


 

 

 

 

@CacheTechShare