Date与Calendar
Date date=new Date();//现在时间
Date date1=new Date(1000);//格林威治时间1997/01/01开始算,后面的是毫秒
Calendar calendar=Calendar.getInstance();//获得一个月历
calendar.set(2016, 0,01);
calendar.setTime(new Date());//setTime的时候才可以用new Date()
int year=calendar.get(Calendar.YEAR),
month=calendar.get(Calendar.MONTH)+1,
day=calendar.get(Calendar.DAY_OF_MONTH),
hour=calendar.get(Calendar.HOUR_OF_DAY),
minute=calendar.get(Calendar.MINUTE),
second=calendar.get(Calendar.SECOND);
System.out.printf("%d,%d,%d,%d,%d,%d\n",year,month,day,hour,minute,second);
System.out.println(date);
计算两个时间差的天数
比如2012/9/1和2016/7/1
Calendar calendar1=Calendar.getInstance();
Calendar calendar2=Calendar.getInstance();
calendar1.set(2012, 9,1);
calendar2.set(2016, 7,1);
long time1=calendar1.getTimeInMillis();//貌似是获得时间绝对值的函数
long time2=calendar2.getTimeInMillis();
System.out.println(Math.abs((time1-time2)/(1000*60*60*24)));
借助Calendar写一个显示日历的类
class CalendarFuck{
int year,month;
String[] getCalendar(){
String []a=new String[43];
Calendar Calender1=Calendar.getInstance();
Calender1.set(year, month-1,1);
int weekday=Calender1.get(Calender1.DAY_OF_WEEK)-1;
// System.out.println(month);
int day = 0;
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12){
day=31;
}else if(month==4||month==6||month==9|month==11)
day=30;
else if(month==2){
if(year%4==0&&year%100!=0||year%400==0)
day=29;
else
day=28;
}
for(int i=0;i<weekday;i++)
a[i]=" ";
for(int i=weekday,n=1;i<weekday+day;i++){
a[i]=String.valueOf(n);
n++;
}
for(int i=weekday+day;i<a.length;i++){
a[i]=" ";
}
return a;
}
}
Date与Calendar的更多相关文章
- Date和Calendar时间操作常用方法及示例
package test; import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date; /** ...
- Java日期与时间的处理/Date,String,Calendar转换
public class Demo01 { //Java中Date类和Calendar简介 public static void main(String[] args) { long now=Syst ...
- Date Picker Calendar For Oracle Forms 6i
Giving date picker calendar option to user for date type fields in Oracle Forms. I am providing you ...
- Freebie: Date Picker Calendar Demo Form For Oracle Forms 6i
I have already posted and provided the required PLSQL Library and the Calendar FMX file in my previo ...
- java日期类型转换总结date timestamp calendar string
用Timestamp来记录日期时间还是很方便的,但有时候显示的时候是不需要小数位后面的毫秒的,这样就需要在转换为String时重新定义格式. Timestamp转化为String: S ...
- Java:Date、Calendar、Timestamp的使用
一.Java.util.Date 该对象包含了年月日时分秒信息.具体使用如下代码: //String 转换为Date private static void dateDemo() throws Par ...
- Java:Date、Calendar、Timestamp的区别、相互转换与使用【转载】
1 Java.util.Date 包含年.月.日.时.分.秒信息 包含年.月.日信息. 继承自java.util.Date.在数据库相关操作中使用,如rs.getDate,ps.setDate等.rs ...
- JAVA 的 Date、Calendar的常用用法
一.Date与String的互转用法,这里需要用到SimpleDateFormat Date date = new Date(); //设置格式 SimpleDateFor ...
- JAVA之旅(二十三)——System,RunTime,Date,Calendar,Math的数学运算
JAVA之旅(二十三)--System,RunTime,Date,Calendar,Math的数学运算 map实在是太难写了,整理得我都晕都转向了,以后看来需要开一个专题来讲这个了,现在我们来时来学习 ...
- java日期和时间Date、Calendar、SimpleDateFormat
1 时间和日期 1.1 日期类Date和格式化SimpleDateFormat 日期使用过程中需要将日期Date对象转化为字符串,或者将字符串形式的日期转化为日期Date对象.可 ...
随机推荐
- Matlab 符号运算
root(p):多项式求根.多项式等于0时对应方程的根. 例:,则输入p=[5 4 3 2 1]; root(p) 注:多项式系数都是按幂指数递减形式的. poly([a,b,c]):求已知根为a,b ...
- infinitescroll 通过无限制分页(json方式完整代码)
@{ ViewBag.Title = " ";} <style type="text/css"> #infscr-loading { text-al ...
- request.getParameterMap();
Map<String, String[]> map = request.getParameterMap(); for(Map.Entry<String,String[]> e: ...
- HBase HFileBlock
HFileBlock官方源码注释: Reading HFile version 1 and 2 blocks, and writing version 2 blocks. In version 1 ...
- JAVA调用.NET WebService终极方案(包含对SoapHeader的处理)
一.前言: 今日部门的产品需要用到短信功能,需要走公司统一的接口,而该短信接口是由.net开发的,利用两天时间彻底搞定了用java来调用.net 的web service,包括对soap h ...
- PHP IDE 框架 服务器 相关
server:nginx 框架:一个比较老的项目用的ZendFramework,最近的新项目用的codeigniter IDE: zend studio Sublime Text https: ...
- Java程序员容易犯的10个错误
1. Array 转 ArrayList 一般开发者喜欢用: List<String> list = Arrays.asList(arr); Arrays.asList() 会返回一个Ar ...
- input上传文件显示图片缩略图
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- struct 结构
//原始套接字学习笔记之代码结构 /* *host端程序结构 */ #include <> #define .. //主函数 int main() { //建立发送线程 pthread_t ...
- Hitting the 2100 parameter limit (SQL Server) when using Contains()
1down vote My solution (Guides -> List of Guid): List<tstTest> tsts = new List<tstTest&g ...