public class DateUtils(){
/**
* 获取网络时间
* @return
*/
public static Date getWebsiteDatetime(){
try {
URL url = new URL("http://www.baidu.com");// 取得资源对象
URLConnection uc = url.openConnection();// 生成连接对象
uc.connect();// 发出连接
long ld = uc.getDate();// 读取网站日期时间
Date date= new Date(ld);// 转换为标准时间对象
returndate;} catch (MalformedURLException e){
e.printStackTrace();} catch (IOException e){
e.printStackTrace();}return null;}}
2.根据查询出来的时间查询本月初的时间
//获取查询出来的网络时间
//我把getWebsiteDatetime() 方法封装到了DateUtils类中,直接调用
Date newTime = DateUtils.getWebsiteDatetime();
//获取本月初时间
Date firstTime = new Date(newTime.getYear(),newTime.getMonth(),01);