
正文
java获得时间戳的代码 如何获取java中的时间戳毫秒值
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
Java获取时间戳精确到年月日时
其实系统默认的都是毫秒数的时间戳, 所以你想要的2017-01-16 17:00:00 不是提取的, 而是格式化的
new SimpleDateFormat("yyyy-MM-dd HH:00:00").format(System.currentTimeMillis());
相关问答
Q1: java 获取昨天,上个星期一,本月开始时间戳,怎么写
昨天
Date date=new Date();//取时间
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
calendar.add(calendar.DATE,-1);//把日期往后增加一天.整数往后推,负数往前移动
date=calendar.getTime(); //这个时间就是日期往后推一天的结果
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = formatter.format(date);
System.out.println(dateString);
星期一
Calendar cal = Calendar.getInstance();
int n = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (n == 0) {
n = 7;
}
cal.add(Calendar.DATE, -(7 + (n - 1)));// 上周一的日期
Date monday = cal.getTime();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = formatter.format(monday);
System.out.println(dateString);
本月开始时间
Calendar cal_1=Calendar.getInstance();//获取当前日期
cal_1.add(Calendar.MONTH, -1);
cal_1.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
String firstDay = format.format(cal_1.getTime());
System.out.println("-----1------firstDay:"+firstDay);
Q2: java怎么获取19位时间戳
public Long getToday(){
DateTime now = new DateTime();
return new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 0, 0, 0, 0).getMillis();
}
public Long getTomorrow(){
DateTime now = new DateTime();
return new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 0, 0, 0, 0).plusDays(1).getMillis();
}
Q3: Java 如何获得 Unix 时间戳
时间戳是从1970年1月1日(UTC/GMT的午夜)开始所经过的秒数,所以可以将当前毫秒时间转换成秒级时间就可以了:
System.currentTimeMillis()/1000L就可以了
Q4: 求助!java中关于时间戳Timestamp的问题
GregorianCalendar gcal = new GregorianCalendar(); // 获得当前时间
// 设定格式yyyy-mm-dd hh:mm:ss
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = gcal.getTime(); // 将当前时间转成日期对象
String datetime = df.format(date); // 获得符合格式的字符串,当前日期时间
int index = datetime.indexOf(" ");
String selectday = datetime.substring(0, index); // 当前日期
// 将当前日期换成Timestamp对象
// string的类型必须形如: yyyy-mm-dd hh:mm:ss[.f...] 这样的格式,中括号表示可选,// 否则报错!!!
Timestamp nowdatetime = Timestamp.valueOf(datetime);
Q5: java获取时间戳
应该用System.out.format函数java获得时间戳的代码,可以给java获得时间戳的代码你实例:
System.out.format(java.util.Locale.US, "%1$ta, %1$td %1$tb %1$tY %1$tT %1$tz", new java.util.Date());
不仅给你实例java获得时间戳的代码,还给你参考文献
最后,采纳即可
java获得时间戳的代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于如何获取java中的时间戳毫秒值、java获得时间戳的代码的信息别忘了在本站进行查找喔。







