java时间戳是什么

java时间戳是什么,第1张

Timestamp就是所谓的时间戳,这个主要用在数据库上,你可以再javasql这个包内找到这个类,一般数据库里如果用Date这个类的话,那你取出来的时候只能到某一天,也就是日,但是Timestamp的话,就是到小时一直到纳秒,很精确的。但是你把时间存进去的时候也要用这个类。比如:mysql的话,你可以用setTimtstamp();这个方法,你可以到java的文档里去看看,里面都写的比较清楚

时间戳是从1970年1月1日(UTC/GMT的午夜)开始所经过的秒数,所以可以将当前毫秒时间转换成秒级时间就可以了:

SystemcurrentTimeMillis()/1000L就可以了

public static void main(String[] args)

{

Timer timer = new Timer();

//5秒后开始执行该任务,且之后每隔10秒执行一次该任务

timerschedule(new MyTask(), 1000, 10000);

}

public class MyTask extends TimerTask

{

@Override

public void run()

{

Systemoutprintln("20140202123120");

}

}

昨天

Date date=new Date();//取时间

Calendar calendar = new GregorianCalendar();

calendarsetTime(date);

calendaradd(calendarDATE,-1);//把日期往后增加一天整数往后推,负数往前移动

date=calendargetTime(); //这个时间就是日期往后推一天的结果

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

String dateString = formatterformat(date);

Systemoutprintln(dateString);

星期一

Calendar cal = CalendargetInstance();

int n = calget(CalendarDAY_OF_WEEK) - 1;

if (n == 0) {

    n = 7;

}

caladd(CalendarDATE, -(7 + (n - 1)));// 上周一的日期

Date monday = calgetTime();

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

String dateString = formatterformat(monday);

Systemoutprintln(dateString);

本月开始时间

Calendar   cal_1=CalendargetInstance();//获取当前日期 

cal_1add(CalendarMONTH, -1);

cal_1set(CalendarDAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天 

String firstDay = formatformat(cal_1getTime());

Systemoutprintln("-----1------firstDay:"+firstDay);

Timestamp timestamp=new Timestamp(new Date()getTime());

Systemoutprintln(timestamptoString());

String timeStr=timestamptoString()substring(0, timestamptoString()indexOf(""));

Systemoutprintln(timeStr);

public Long getToday(){

DateTime now = new DateTime();

return new DateTime(nowgetYear(), nowgetMonthOfYear(), nowgetDayOfMonth(), 0, 0, 0, 0)getMillis();

}

public Long getTomorrow(){

DateTime now = new DateTime();

return new DateTime(nowgetYear(), nowgetMonthOfYear(), nowgetDayOfMonth(), 0, 0, 0, 0)plusDays(1)getMillis();

}

以上就是关于java时间戳是什么全部的内容,包括:java时间戳是什么、Java 如何获得 Unix 时间戳、java中如何 使用时间戳,在一定内返回同一个数值。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/9615943.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-30
下一篇2023-04-30

发表评论

登录后才能评论

评论列表(0条)

    保存