nbcj.net
当前位置:首页 >> jAvA当前时间加一 >>

jAvA当前时间加一

不用那么繁杂的操作,下面即可: Calendar now=Calendar.getInstance(); now.add(Calendar.MINUTE,30); SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateStr=sdf.format(now.getTimeInMillis()); System.out.pri...

java在当前系统时间加一天主要是使用calendar类的add方法,如下代码: import java.util.Calendar;import java.util.Date;public class ceshi {public static void main(String[] args) {Date date = new Date();// 新建此时的的系统时间System....

import java.util.Date; public class Demo { public static void main(String[] args) { Date date = new Date();//当前时间 int addDay = 2;//加两天 date.setDate(date.getDate()+addDay); System.out.println(date.toLocaleString()); } }

你试下下面代码: Calendar cal = Calendar.getInstance(); //下面的就是把当前日期加一个月 cal.add(Calendar.MONTH, 1); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); System.out.println("today is:" + format.format(Cal...

推迟一周示例:Calendar curr = Calendar.getInstance();curr.set(Calendar.DAY_OF_MONTH,curr.get(Calendar.DAY_OF_MONTH)+7);Date date=curr.getTime(); 推迟一年示例:Calendar curr = Calendar.getInstance();curr.set(Calendar.YEAR,curr.g...

用 add方法,不是set. 应该是: cal.add(Calendar.DAY_OF_MONTH, 1);示例:package com.demo;import java.util.Calendar;import java.util.Date;public class test {public static void main(String ars[]) {Date t1 = new Date();Calendar cal ...

加12个月也就是加一年嘛 代码如下: import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;import java.util.Scanner;public class Test {public static void main(String[] args) {Scanner sc = new Scanner(Sy...

long currentTime = System.currentTimeMillis() + 30 * 60 * 1000; Date date = new Date(currentTime); DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String nowTime=""; nowTime= df.format(date); System.out.println(now...

public static void main(String args[]) { //new一个date对象 Date d = new Date(); long t = d.getTime();//获取当前的毫秒数 t+=(6*24*60*60*1000);//当前毫秒数加上一天的毫秒数(1*24*60*60*1000) d.setTime(t);//将总毫秒数重新赋值给date...

Calendar calendar = Calendar.getInstance(); /* HOUR_OF_DAY 指示一天中的小时 */ calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - 1); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Syste...

网站首页 | 网站地图
All rights reserved Powered by www.nbcj.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com