首页 > 编程 > Java > 正文

java获取当前日期使用实例

2019-11-26 15:49:08
字体:
来源:转载
供稿:网友

复制代码 代码如下:

package com.infomorrow.dao;


import java.sql.Timestamp;
import java.util.Calendar;
import java.util.TimeZone;

import org.junit.Test;

public class test_date {
@Test
public void test(){
    Timestamp today = new Timestamp(Calendar.getInstance(TimeZone.getTimeZone("GMT+8")).getTimeInMillis());
    int year=today.getYear()+1900;
    int month=today.getMonth()+1;
    int day = today.getDate();
    String date = year+"-"+month+"-"+day;
    System.out.println("date:"+date);
    System.out.println(today);
    }
}
//输出
date:2013-12-17
2013-12-17 13:04:30.809

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表