① java中Calendar类中getTimeInMillis()方法返回值是什么
返回从格林威治标准时间 1970 年 1 月 1 日的 00:00:00.000到Calendar对象表示的时间之间的毫秒数
② 在java中怎么获取北京时间
一般情况可以用直接用Date类,例如:
Date date = new Date(System.currentTimeMillis()); System.out.println(date);先用System.currentTimeMillis()是得到系统当前时间。然后输出就可以了。
但是如果要更加准确的话,最好用Calendar类,因为可能用你的程序的系统不是中国的,用Date date = new Date(System.currentTimeMillis())得到的就是不是北京时间了。所以可以用Calendar calendar = Calendar.getInstance(Locale.CHINA);
还可以用SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");来格式化时间。下面是一个简单的实例:
publicclassGetTime
{
publicstaticvoidmain(String[]args)
{
Calendarcalendar=Calendar.getInstance(Locale.CHINA);
Datedate=calendar.getTime();
SimpleDateFormatdateFormat=newSimpleDateFormat("yyyy-MM-ddHH:mm:ss");
StringdateString=dateFormat.format(date);
System.out.println(dateString);
}
}
导入包的时候Date类是java.util下的Date类,java.util.Date;
③ JAVA中的格林威治时间问题。
使用java类库中的Calendar.time啊。
GregorianCalendar now = new GregorianCalendar();
int hour=now.get(Calendar.HOUR);
int min =now.get(Calendar.MINUTE);
④ java获取系统时间不正确, 比实际时间早8小时。如何解决
用Calendar.getInstance 取时间时带上时区参数,8小时让人猜想你取的是格林尼治时间,换算东八区的时间正好。
⑤ 请问,在java中怎样获取系统时间,注意不是“格林威治时间”
Date date = new Date();
int day=date.getDay();//年
int month=date.getMonth();//月
int year=date.getYear();//日
System.out.println(year+"/"+month+"/"+day);//输出xxxx/xx/xx
还有时分秒用同样的方式获得
另外一种方式请看我的blog
http://dingkui1983.spaces.live.com/?_c11_blogpart_blogpart=blogview&_c=blogpart&partqs=amonth%3d8%26ayear%3d2006 "日期转换"
⑥ java 从数据库的表中两个列获取两个时间(时间为字符型),相减,结果以时间形式输出。
将两个时间先转为date型,然后获取两个时间的格林威治时间毫秒数,计算毫秒差,再讲其转换为date型就可以了
⑦ java中如何设置时间和显示时间
JAVA中获取当前系统时间2011-07-06 20:45 并格式化输出:
import java.util.Date;
import java.text.SimpleDateFormat;
public class NowString {
public static void main(String[] args) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
}
}
设置时间,推荐 使用java.util.Calendar类来进行操作,
import java.util.Date;
import java.util.Calendar;
import java.text.SimpleDateFormat;
public class TestDate{
public static void main(String[] args){
Date now = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");//可以方便地修改日期格式
String hehe = dateFormat.format( now );
System.out.println(hehe);
Calendar c = Calendar.getInstance();//可以对每个时间域单独修改
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int date = c.get(Calendar.DATE);
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
int second = c.get(Calendar.SECOND);
System.out.println(year + "/" + month + "/" + date + " " +hour + ":" +minute + ":" + second);
}
}
⑧ java 时间 为格林威治
System.out.println(new Date(System.currentTimeMillis()).toLocaleString());
⑨ 通过java计算:已知秒数如何通过格林威治时间计算出具体的时间
String strRetDeat = "";
calentdar.setTimeInMillis(120000000);
Date date = calentdar.getTime();
//
String pattern="yyyy-MM-dd hh:mm:ss";
SimpleDateFormat format=new SimpleDateFormat(pattern);
strRetDeat=format.format(date);
System.out.println(strRetDeat);
⑩ 现在 需要写一个 根据时间 以及此时间所在时区 获取到 对应的格林威治时间 怎么做 java
TimeZone zone1 = TimeZone.getTimeZone("GMT+8");
TimeZone zone2 = TimeZone.getTimeZone("GMT+4");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
sdf.setTimeZone(zone1);