- 浏览: 3511445 次
- 性别:
- 来自: 杭州
文章分类
- 全部博客 (1491)
- Hibernate (28)
- spring (37)
- struts2 (19)
- jsp (12)
- servlet (2)
- mysql (24)
- tomcat (3)
- weblogic (1)
- ajax (36)
- jquery (47)
- html (43)
- JS (32)
- ibatis (0)
- DWR (3)
- EXTJS (43)
- Linux (15)
- Maven (3)
- python (8)
- 其他 (8)
- JAVASE (6)
- java javase string (0)
- JAVA 语法 (3)
- juddiv3 (15)
- Mule (1)
- jquery easyui (2)
- mule esb (1)
- java (644)
- log4j (4)
- weka (12)
- android (257)
- web services (4)
- PHP (1)
- 算法 (18)
- 数据结构 算法 (7)
- 数据挖掘 (4)
- 期刊 (6)
- 面试 (5)
- C++ (1)
- 论文 (10)
- 工作 (1)
- 数据结构 (6)
- JAVA配置 (1)
- JAVA垃圾回收 (2)
- SVM (13)
- web st (1)
- jvm (7)
- weka libsvm (1)
- weka屈伟 (1)
- job (2)
- 排序 算法 面试 (3)
- spss (2)
- 搜索引擎 (6)
- java 爬虫 (6)
- 分布式 (1)
- data ming (1)
- eclipse (6)
- 正则表达式 (1)
- 分词器 (2)
- 张孝祥 (1)
- solr (3)
- nutch (1)
- 爬虫 (4)
- lucene (3)
- 狗日的腾讯 (1)
- 我的收藏网址 (13)
- 网络 (1)
- java 数据结构 (22)
- ACM (7)
- jboss (0)
- 大纸 (10)
- maven2 (0)
- elipse (0)
- SVN使用 (2)
- office (1)
- .net (14)
- extjs4 (2)
- zhaopin (0)
- C (2)
- spring mvc (5)
- JPA (9)
- iphone (3)
- css (3)
- 前端框架 (2)
- jui (1)
- dwz (1)
- joomla (1)
- im (1)
- web (2)
- 1 (0)
- 移动UI (1)
- java (1)
- jsoup (1)
- 管理模板 (2)
- javajava (1)
- kali (7)
- 单片机 (1)
- 嵌入式 (1)
- mybatis (2)
- layui (7)
- asp (12)
- asp.net (1)
- sql (1)
- c# (4)
- andorid (1)
- 地价 (1)
- yihuo (1)
- oracle (1)
最新评论
-
endual:
https://blog.csdn.net/chenxbxh2 ...
IE6 bug -
ice86rain:
你好,ES跑起来了吗?我的在tomcat启动时卡在这里Hibe ...
ES架构技术介绍 -
TopLongMan:
...
java public ,protect,friendly,private的方法权限(转) -
贝塔ZQ:
java实现操作word中的表格内容,用插件实现的话,可以试试 ...
java 读取 doc poi读取word中的表格(转) -
ysj570440569:
Maven多模块spring + springMVC + JP ...
Spring+SpringMVC+JPA
问答首页 → Java编程和Java企业应用 → Hibernate
关于String类型转换成Date,再转换成String类型的问题!
悬赏:5 发布时间:2009-03-19 提问人:幽灵线程 (初级程序员)
< > 猎头职位: 上海: 上海:天会皓闻诚聘资深Java架构师
我最近一周在做一个练习项目,
用的是自己写的Struts1和Hibernate3框架。
有一个存储Date型数据很麻烦,不能解决。
如下:
1.给前台一个Date类型数据date赋值,格式为:2009-1-1
2.给struts的form对象赋值,类型为Date,格式为:非2009-1-1
3,给form对应的持久化对象po赋值,格式为:格式为:非2009-1-1
4.在hibernate构造sql语句时,需要 格式为:2009-1-1 的String数据类型,这里却得不到了。(关键是这里)
(我的sql语句为 insert into tablename values ( to_date('2009-1-1','yyyy-mm-dd') ))
问题概括:将 格式为2009-1-1的String ,转成 Date ,再转成 String:"2009-1-1"。
多问一句,各位朋友的存储日期用什么手段!
该问题已经关闭: 超过15天由系统自动关闭,悬赏平分给所有参与回答的会员
问题答案可能在这里 → 寻找更多解答
* Java获取各种常用时间方法
* Calendar常用方法封装
* 分享一个关于日期常用操作工具类
* DateField存储格式的问题?
* java 求某个月中星期天的个数 算法
回答
insert into tablename values ( to_date('2009-1-1','yyyy-m-d') ))
airu (初级程序员) 2009-03-19
存储日期就用java.util.Date 你hbm.xml里面配置他的类型为java.util.Date,
你从页面提交过来的时间,struts会自动帮你生成指定的Date对象赋值的
你尽然用到了Hibernate就不用关心他的Sql语句了.
比如你的类是这样的
Java代码 收藏代码
1. public class Student{
2. private Date date;//java.util.Date类型的
3. //setter..getter...
4. }
public class Student{
private Date date;//java.util.Date类型的
//setter..getter...
}
然后在你Student.hbm.xml配置文件里面你配置这个字段的类型为java.util.Date就可,或者不用配置他的类型就一个<property name="date"/> 他也会自动配置的.
然后你要保存页面提交过来的日期数据的时候(就是你要执行那条保存语句的时候)
你只要如下就可以了
Java代码 收藏代码
1. //假如下面的方法可以正确获得Hierbante的Session
2. public void test(){
3. Student t = new Student();
4. t.setDate(new Date);//加入这个的日期是从页面获得过来的,你可以通过form.getDate()来设置.
5. //然后你直接保存就可以了,hibnerate 会自动帮你生成语句并且执行保存数据的
6. session.save(t);//注意要提交事务才能真正的执行
7. }
//假如下面的方法可以正确获得Hierbante的Session
public void test(){
Student t = new Student();
t.setDate(new Date);//加入这个的日期是从页面获得过来的,你可以通过form.getDate()来设置.
//然后你直接保存就可以了,hibnerate 会自动帮你生成语句并且执行保存数据的
session.save(t);//注意要提交事务才能真正的执行
}
yourgame (CTO) 2009-03-20
发给你一个我自己写的
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
/**
* @author Leonel Wong
* @version 1.0.0
* @create 2008-07-24 10:10
* @see 处理时间(包括时间格式的类)
*/
public class DateUtils {
/**
* 取时间年的格式代码
*/
public static String YEAR = "yyyy";
/**
* 取时间月的格式代码
*/
public static String MONTH = "MM";
/**
* 取时间日的格式代码
*/
public static String DAY = "dd";
/**
* 取时间时的格式代码
*/
public static String HOUR = "hh";
/**
* 取时间24小时制的格式代码
*/
public static String HOUR_24 = "HH";
/**
* 取时间分的格式代码
*/
public static String MIMUTE = "mm";
/**
* 取时间秒的格式代码
*/
public static String SECOND = "ss";
/**
* 取时间毫秒的格式代码
*/
public static String MILLISECOND = "SS";
/**
* 格式为yyyy-MM-dd的时间
*/
public static String YMD_FORMAT = YEAR + "-" + MONTH + "-" + DAY;
/**
* 格式为yyyy-MM-dd HH:mm:ss的时间
*/
public static String YMDHMS_FORMAT = YEAR + "-" + MONTH + "-" + DAY + " "
+ HOUR_24 + ":" + MIMUTE + ":" + SECOND;
/**
* 格式为yyyy-MM-dd HH:mm:ss:SS的时间
*/
public static String UTILTIME_FORMAT = YEAR + "-" + MONTH + "-" + DAY + " "
+ HOUR_24 + ":" + MIMUTE + ":" + SECOND + ":" + MILLISECOND;
/**
* 格式为yyyyMMddHHmmssSS的时间
*/
public static String CRITERIONTIME_FORMAT = YEAR + MONTH + DAY + HOUR_24
+ MIMUTE + SECOND + MILLISECOND;
/**
* @author 王磊
* @see 2008-03-08 获得yy-mm-dd格式的时间
* @return String date
*/
public static String getYearMonthDay() {
return getDateByFormat(YEAR + "-" + MONTH + "-" + DAY);
}
/**
* @see 返回格式为yyyy-MM-dd HH:mm:ss:SS的时间字符串
* @return String date
*/
public static String getNOWTime_0() {
return getDateByFormat(UTILTIME_FORMAT);
}
/**
* @see 返回格式为yyyyMMddHHmmssSS的时间字符串
* @return String date
*/
public static String getNOWTime_1() {
return getDateByFormat(CRITERIONTIME_FORMAT);
}
/**
* @see 获得指定时间格式
* @param String
* format 时间格式
* @return String dateStr 返回获得相应格式时间的字符串
*/
public static String getDateByFormat(String format) {
String dateStr = "";
try {
if (format != null) {
Date date = new Date(System.currentTimeMillis());
SimpleDateFormat simFormat = new SimpleDateFormat(format,
Locale.CHINA);
dateStr = simFormat.format(date);
}
} catch (Exception e) {
e.printStackTrace();
}
return dateStr;
}
/**
* @see 获得指定时间格式
* @param Date
* date 时间
* @param String
* format 时间格式
* @return String dateStr 返回获得相应格式时间的字符串
*/
public static String getDateByFormatYMD(Date date) {
String dateStr = "";
try {
SimpleDateFormat simFormat = new SimpleDateFormat(YMD_FORMAT,
Locale.CHINA);
dateStr = simFormat.format(date);
} catch (Exception e) {
e.printStackTrace();
}
return dateStr;
}
/**
* @see 获得指定时间格式
* @param Date
* date 时间
* @param String
* format 时间格式
* @return String dateStr 返回获得相应格式时间的字符串
*/
public static String getDateByFormat(Date date, String format) {
String dateStr = "";
try {
if (format != null) {
SimpleDateFormat simFormat = new SimpleDateFormat(format,
Locale.CHINA);
dateStr = simFormat.format(date);
}
} catch (Exception e) {
e.printStackTrace();
}
return dateStr;
}
/**
* @see 获得当前时间
* @return Date date
*/
public static Date getNOWTime() {
return new Date(System.currentTimeMillis());
}
/**
* @see 把字符串类型的时间转换为yyyy-MM-dd的时间格式
*/
public static Date getDateByStrToYMD(String str) {
Date date = null;
if (str != null && str.trim().length() > 0) {
DateFormat dFormat = new SimpleDateFormat(YMD_FORMAT);
try {
date = dFormat.parse(str);
} catch (ParseException e) {
e.printStackTrace();
}
}
return date;
}
/**
* @see 把字符串类型的时间转换为自定义格式的时间
*/
public static Date getDateByStrToFormat(String format, String str) {
DateFormat dFormat = new SimpleDateFormat(format);
Date date = null;
try {
if (str != null) {
date = dFormat.parse(str);
}
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
/**
* 功能:判断输入年份是否为闰年<br>
*
* @param year
* @return 是:true 否:false
* @author pure
*/
public static boolean leapYear(int year) {
boolean leap;
if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0) {
leap = true;
} else {
leap = false;
}
} else {
leap = true;
}
} else
leap = false;
return leap;
}
/**
* 功能:得到指定月份的月底 格式为:xxxx-yy-zz (eg: 2007-12-31)<br>
*
* @param String
* @return String
*/
public static String getEndOfMonth(String str) {
int tyear = Integer.parseInt(getDateByFormat(getDateByStrToYMD(str),
YEAR));
int tmonth = Integer.parseInt(getDateByFormat(getDateByStrToYMD(str),
MONTH));
String strtmonth = null;
String strZ = null;
if (tmonth == 1 || tmonth == 3 || tmonth == 5 || tmonth == 7
|| tmonth == 8 || tmonth == 10 || tmonth == 12) {
strZ = "31";
}
if (tmonth == 4 || tmonth == 6 || tmonth == 9 || tmonth == 11) {
strZ = "30";
}
if (tmonth == 2) {
if (leapYear(tyear)) {
strZ = "29";
} else {
strZ = "28";
}
}
strtmonth = tmonth >= 10 ? String.valueOf(tmonth) : ("0" + tmonth);
return tyear + "-" + strtmonth + "-" + strZ;
}
public static String getEndOfMonth(int tyear, int tmonth) {
String strtmonth = null;
String strZ = null;
if (tmonth == 1 || tmonth == 3 || tmonth == 5 || tmonth == 7
|| tmonth == 8 || tmonth == 10 || tmonth == 12) {
strZ = "31";
}
if (tmonth == 4 || tmonth == 6 || tmonth == 9 || tmonth == 11) {
strZ = "30";
}
if (tmonth == 2) {
if (leapYear(tyear)) {
strZ = "29";
} else {
strZ = "28";
}
}
strtmonth = tmonth >= 10 ? String.valueOf(tmonth) : ("0" + tmonth);
return tyear + "-" + strtmonth + "-" + strZ;
}
/**
* 功能:得到指定月份的月初 格式为:xxxx-yy-zz (eg: 2007-12-01)<br>
*
* @param String
* @return String
*/
public static String getStartOfMonth(int tyear, int tmonth) {
String strtmonth = tmonth >= 10 ? String.valueOf(tmonth)
: ("0" + tmonth);
return tyear + "-" + strtmonth + "-" + "01";
}
public static String getStartOfMonth(String str) {
int tyear = Integer.parseInt(getDateByFormat(getDateByStrToYMD(str),
YEAR));
int tmonth = Integer.parseInt(getDateByFormat(getDateByStrToYMD(str),
MONTH));
String strtmonth = tmonth >= 10 ? String.valueOf(tmonth)
: ("0" + tmonth);
return tyear + "-" + strtmonth + "-" + "01";
}
/**
* 功能:得到指定月份的月初 格式为:xxxx-yy-zz (eg: 2007-12-01)<br>
*
* @param String
* @return String
*/
public static int getMonthCountBySQU(String start, String end) {
int syear = Integer.parseInt(getDateByFormat(getDateByStrToYMD(start),
YEAR));
int smonth = Integer.parseInt(getDateByFormat(getDateByStrToYMD(start),
MONTH));
int eyear = Integer.parseInt(getDateByFormat(getDateByStrToYMD(start),
YEAR));
int emonth = Integer.parseInt(getDateByFormat(getDateByStrToYMD(start),
MONTH));
return (eyear - syear) * 12 + (emonth - smonth) + 1;
}
/**
* 获得时间序列 EG:2008-01-01~2008-01-31,2008-02-01~2008-02-29
*/
public static List getMonthSqu(String fromDate, String toDate) {
List list = new ArrayList();
int count = getMonthCountBySQU(fromDate, toDate);
int syear = Integer.parseInt(getDateByFormat(
getDateByStrToYMD(fromDate), YEAR));
int smonth = Integer.parseInt(getDateByFormat(
getDateByStrToYMD(fromDate), MONTH));
int eyear = Integer.parseInt(getDateByFormat(getDateByStrToYMD(toDate),
YEAR));
String startDate = fromDate;
String endDate = "";
for (int i = 1; i <= count; i++) {
if (syear <= eyear) {
startDate = getStartOfMonth(syear, smonth);
endDate = getEndOfMonth(syear, smonth);
list.add(startDate + "~" + endDate);
System.out.println(startDate + "~" + endDate);
if (smonth == 13) {
smonth = 1;
syear++;
}
smonth++;
}
}
return list;
}
/**
* 通过传入的时间来获得所属周内的时间
* @param start
* @param num
* @return
*/
public static String getDateOFWeekByDate(String start, int num) {
Date dd = getDateByStrToYMD(start);
Calendar c = Calendar.getInstance();
c.setTime(dd);
if (num==1) // 返回星期一所在的日期
c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
else if (num==2) // 返回星期二所在的日期
c.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY);
else if (num==3) // 返回星期三所在的日期
c.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY);
else if (num==4) // 返回星期四所在的日期
c.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY);
else if (num==5) // 返回星期五所在的日期
c.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
else if (num==6) // 返回星期六所在的日期
c.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
else if (num==0) // 返回星期日所在的日期
c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
return getDateByFormatYMD(c.getTime());
}
}
关于String类型转换成Date,再转换成String类型的问题!
悬赏:5 发布时间:2009-03-19 提问人:幽灵线程 (初级程序员)
< > 猎头职位: 上海: 上海:天会皓闻诚聘资深Java架构师
我最近一周在做一个练习项目,
用的是自己写的Struts1和Hibernate3框架。
有一个存储Date型数据很麻烦,不能解决。
如下:
1.给前台一个Date类型数据date赋值,格式为:2009-1-1
2.给struts的form对象赋值,类型为Date,格式为:非2009-1-1
3,给form对应的持久化对象po赋值,格式为:格式为:非2009-1-1
4.在hibernate构造sql语句时,需要 格式为:2009-1-1 的String数据类型,这里却得不到了。(关键是这里)
(我的sql语句为 insert into tablename values ( to_date('2009-1-1','yyyy-mm-dd') ))
问题概括:将 格式为2009-1-1的String ,转成 Date ,再转成 String:"2009-1-1"。
多问一句,各位朋友的存储日期用什么手段!
该问题已经关闭: 超过15天由系统自动关闭,悬赏平分给所有参与回答的会员
问题答案可能在这里 → 寻找更多解答
* Java获取各种常用时间方法
* Calendar常用方法封装
* 分享一个关于日期常用操作工具类
* DateField存储格式的问题?
* java 求某个月中星期天的个数 算法
回答
insert into tablename values ( to_date('2009-1-1','yyyy-m-d') ))
airu (初级程序员) 2009-03-19
存储日期就用java.util.Date 你hbm.xml里面配置他的类型为java.util.Date,
你从页面提交过来的时间,struts会自动帮你生成指定的Date对象赋值的
你尽然用到了Hibernate就不用关心他的Sql语句了.
比如你的类是这样的
Java代码 收藏代码
1. public class Student{
2. private Date date;//java.util.Date类型的
3. //setter..getter...
4. }
public class Student{
private Date date;//java.util.Date类型的
//setter..getter...
}
然后在你Student.hbm.xml配置文件里面你配置这个字段的类型为java.util.Date就可,或者不用配置他的类型就一个<property name="date"/> 他也会自动配置的.
然后你要保存页面提交过来的日期数据的时候(就是你要执行那条保存语句的时候)
你只要如下就可以了
Java代码 收藏代码
1. //假如下面的方法可以正确获得Hierbante的Session
2. public void test(){
3. Student t = new Student();
4. t.setDate(new Date);//加入这个的日期是从页面获得过来的,你可以通过form.getDate()来设置.
5. //然后你直接保存就可以了,hibnerate 会自动帮你生成语句并且执行保存数据的
6. session.save(t);//注意要提交事务才能真正的执行
7. }
//假如下面的方法可以正确获得Hierbante的Session
public void test(){
Student t = new Student();
t.setDate(new Date);//加入这个的日期是从页面获得过来的,你可以通过form.getDate()来设置.
//然后你直接保存就可以了,hibnerate 会自动帮你生成语句并且执行保存数据的
session.save(t);//注意要提交事务才能真正的执行
}
yourgame (CTO) 2009-03-20
发给你一个我自己写的
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
/**
* @author Leonel Wong
* @version 1.0.0
* @create 2008-07-24 10:10
* @see 处理时间(包括时间格式的类)
*/
public class DateUtils {
/**
* 取时间年的格式代码
*/
public static String YEAR = "yyyy";
/**
* 取时间月的格式代码
*/
public static String MONTH = "MM";
/**
* 取时间日的格式代码
*/
public static String DAY = "dd";
/**
* 取时间时的格式代码
*/
public static String HOUR = "hh";
/**
* 取时间24小时制的格式代码
*/
public static String HOUR_24 = "HH";
/**
* 取时间分的格式代码
*/
public static String MIMUTE = "mm";
/**
* 取时间秒的格式代码
*/
public static String SECOND = "ss";
/**
* 取时间毫秒的格式代码
*/
public static String MILLISECOND = "SS";
/**
* 格式为yyyy-MM-dd的时间
*/
public static String YMD_FORMAT = YEAR + "-" + MONTH + "-" + DAY;
/**
* 格式为yyyy-MM-dd HH:mm:ss的时间
*/
public static String YMDHMS_FORMAT = YEAR + "-" + MONTH + "-" + DAY + " "
+ HOUR_24 + ":" + MIMUTE + ":" + SECOND;
/**
* 格式为yyyy-MM-dd HH:mm:ss:SS的时间
*/
public static String UTILTIME_FORMAT = YEAR + "-" + MONTH + "-" + DAY + " "
+ HOUR_24 + ":" + MIMUTE + ":" + SECOND + ":" + MILLISECOND;
/**
* 格式为yyyyMMddHHmmssSS的时间
*/
public static String CRITERIONTIME_FORMAT = YEAR + MONTH + DAY + HOUR_24
+ MIMUTE + SECOND + MILLISECOND;
/**
* @author 王磊
* @see 2008-03-08 获得yy-mm-dd格式的时间
* @return String date
*/
public static String getYearMonthDay() {
return getDateByFormat(YEAR + "-" + MONTH + "-" + DAY);
}
/**
* @see 返回格式为yyyy-MM-dd HH:mm:ss:SS的时间字符串
* @return String date
*/
public static String getNOWTime_0() {
return getDateByFormat(UTILTIME_FORMAT);
}
/**
* @see 返回格式为yyyyMMddHHmmssSS的时间字符串
* @return String date
*/
public static String getNOWTime_1() {
return getDateByFormat(CRITERIONTIME_FORMAT);
}
/**
* @see 获得指定时间格式
* @param String
* format 时间格式
* @return String dateStr 返回获得相应格式时间的字符串
*/
public static String getDateByFormat(String format) {
String dateStr = "";
try {
if (format != null) {
Date date = new Date(System.currentTimeMillis());
SimpleDateFormat simFormat = new SimpleDateFormat(format,
Locale.CHINA);
dateStr = simFormat.format(date);
}
} catch (Exception e) {
e.printStackTrace();
}
return dateStr;
}
/**
* @see 获得指定时间格式
* @param Date
* date 时间
* @param String
* format 时间格式
* @return String dateStr 返回获得相应格式时间的字符串
*/
public static String getDateByFormatYMD(Date date) {
String dateStr = "";
try {
SimpleDateFormat simFormat = new SimpleDateFormat(YMD_FORMAT,
Locale.CHINA);
dateStr = simFormat.format(date);
} catch (Exception e) {
e.printStackTrace();
}
return dateStr;
}
/**
* @see 获得指定时间格式
* @param Date
* date 时间
* @param String
* format 时间格式
* @return String dateStr 返回获得相应格式时间的字符串
*/
public static String getDateByFormat(Date date, String format) {
String dateStr = "";
try {
if (format != null) {
SimpleDateFormat simFormat = new SimpleDateFormat(format,
Locale.CHINA);
dateStr = simFormat.format(date);
}
} catch (Exception e) {
e.printStackTrace();
}
return dateStr;
}
/**
* @see 获得当前时间
* @return Date date
*/
public static Date getNOWTime() {
return new Date(System.currentTimeMillis());
}
/**
* @see 把字符串类型的时间转换为yyyy-MM-dd的时间格式
*/
public static Date getDateByStrToYMD(String str) {
Date date = null;
if (str != null && str.trim().length() > 0) {
DateFormat dFormat = new SimpleDateFormat(YMD_FORMAT);
try {
date = dFormat.parse(str);
} catch (ParseException e) {
e.printStackTrace();
}
}
return date;
}
/**
* @see 把字符串类型的时间转换为自定义格式的时间
*/
public static Date getDateByStrToFormat(String format, String str) {
DateFormat dFormat = new SimpleDateFormat(format);
Date date = null;
try {
if (str != null) {
date = dFormat.parse(str);
}
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
/**
* 功能:判断输入年份是否为闰年<br>
*
* @param year
* @return 是:true 否:false
* @author pure
*/
public static boolean leapYear(int year) {
boolean leap;
if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0) {
leap = true;
} else {
leap = false;
}
} else {
leap = true;
}
} else
leap = false;
return leap;
}
/**
* 功能:得到指定月份的月底 格式为:xxxx-yy-zz (eg: 2007-12-31)<br>
*
* @param String
* @return String
*/
public static String getEndOfMonth(String str) {
int tyear = Integer.parseInt(getDateByFormat(getDateByStrToYMD(str),
YEAR));
int tmonth = Integer.parseInt(getDateByFormat(getDateByStrToYMD(str),
MONTH));
String strtmonth = null;
String strZ = null;
if (tmonth == 1 || tmonth == 3 || tmonth == 5 || tmonth == 7
|| tmonth == 8 || tmonth == 10 || tmonth == 12) {
strZ = "31";
}
if (tmonth == 4 || tmonth == 6 || tmonth == 9 || tmonth == 11) {
strZ = "30";
}
if (tmonth == 2) {
if (leapYear(tyear)) {
strZ = "29";
} else {
strZ = "28";
}
}
strtmonth = tmonth >= 10 ? String.valueOf(tmonth) : ("0" + tmonth);
return tyear + "-" + strtmonth + "-" + strZ;
}
public static String getEndOfMonth(int tyear, int tmonth) {
String strtmonth = null;
String strZ = null;
if (tmonth == 1 || tmonth == 3 || tmonth == 5 || tmonth == 7
|| tmonth == 8 || tmonth == 10 || tmonth == 12) {
strZ = "31";
}
if (tmonth == 4 || tmonth == 6 || tmonth == 9 || tmonth == 11) {
strZ = "30";
}
if (tmonth == 2) {
if (leapYear(tyear)) {
strZ = "29";
} else {
strZ = "28";
}
}
strtmonth = tmonth >= 10 ? String.valueOf(tmonth) : ("0" + tmonth);
return tyear + "-" + strtmonth + "-" + strZ;
}
/**
* 功能:得到指定月份的月初 格式为:xxxx-yy-zz (eg: 2007-12-01)<br>
*
* @param String
* @return String
*/
public static String getStartOfMonth(int tyear, int tmonth) {
String strtmonth = tmonth >= 10 ? String.valueOf(tmonth)
: ("0" + tmonth);
return tyear + "-" + strtmonth + "-" + "01";
}
public static String getStartOfMonth(String str) {
int tyear = Integer.parseInt(getDateByFormat(getDateByStrToYMD(str),
YEAR));
int tmonth = Integer.parseInt(getDateByFormat(getDateByStrToYMD(str),
MONTH));
String strtmonth = tmonth >= 10 ? String.valueOf(tmonth)
: ("0" + tmonth);
return tyear + "-" + strtmonth + "-" + "01";
}
/**
* 功能:得到指定月份的月初 格式为:xxxx-yy-zz (eg: 2007-12-01)<br>
*
* @param String
* @return String
*/
public static int getMonthCountBySQU(String start, String end) {
int syear = Integer.parseInt(getDateByFormat(getDateByStrToYMD(start),
YEAR));
int smonth = Integer.parseInt(getDateByFormat(getDateByStrToYMD(start),
MONTH));
int eyear = Integer.parseInt(getDateByFormat(getDateByStrToYMD(start),
YEAR));
int emonth = Integer.parseInt(getDateByFormat(getDateByStrToYMD(start),
MONTH));
return (eyear - syear) * 12 + (emonth - smonth) + 1;
}
/**
* 获得时间序列 EG:2008-01-01~2008-01-31,2008-02-01~2008-02-29
*/
public static List getMonthSqu(String fromDate, String toDate) {
List list = new ArrayList();
int count = getMonthCountBySQU(fromDate, toDate);
int syear = Integer.parseInt(getDateByFormat(
getDateByStrToYMD(fromDate), YEAR));
int smonth = Integer.parseInt(getDateByFormat(
getDateByStrToYMD(fromDate), MONTH));
int eyear = Integer.parseInt(getDateByFormat(getDateByStrToYMD(toDate),
YEAR));
String startDate = fromDate;
String endDate = "";
for (int i = 1; i <= count; i++) {
if (syear <= eyear) {
startDate = getStartOfMonth(syear, smonth);
endDate = getEndOfMonth(syear, smonth);
list.add(startDate + "~" + endDate);
System.out.println(startDate + "~" + endDate);
if (smonth == 13) {
smonth = 1;
syear++;
}
smonth++;
}
}
return list;
}
/**
* 通过传入的时间来获得所属周内的时间
* @param start
* @param num
* @return
*/
public static String getDateOFWeekByDate(String start, int num) {
Date dd = getDateByStrToYMD(start);
Calendar c = Calendar.getInstance();
c.setTime(dd);
if (num==1) // 返回星期一所在的日期
c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
else if (num==2) // 返回星期二所在的日期
c.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY);
else if (num==3) // 返回星期三所在的日期
c.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY);
else if (num==4) // 返回星期四所在的日期
c.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY);
else if (num==5) // 返回星期五所在的日期
c.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
else if (num==6) // 返回星期六所在的日期
c.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
else if (num==0) // 返回星期日所在的日期
c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
return getDateByFormatYMD(c.getTime());
}
}
发表评论
-
犯规犯规犯规
2015-09-18 16:45 1314http://bbs.hupu.com/4466597.htm ... -
快速掌握Hibernate中悲观锁和乐观锁
2012-10-19 21:33 1578快速掌握Hibernate ... -
Hibernate延迟加载机制
2012-10-19 21:22 1345Hibernate延迟加载 ... -
Hibernate 子类中不能用session 操作数据库
2012-08-28 14:46 1709Object obj = this.g ... -
hibernate3 下载网址
2012-08-28 12:53 1911我的天啊,居然找个hibernate下载的地址也找了半天 h ... -
师父告诉我诀窍
2012-08-23 16:53 1476<value>classpath*:com ... -
spring 整合 hibernate
2012-07-28 10:41 14691.闲话少说了,先看版本吧。 2.在看要导入的包吧: ... -
使用spring的hibernateTemplate的方法 (转)
2012-07-24 17:12 1508使用spr ... -
hibernate 增删改查
2012-07-24 00:07 1838mysql中库表News,字段如下 id | i ... -
hibernate的对象映射配置文件中属性的介绍和说明
2012-03-04 13:45 1675持久化对象之间一对一的关联关系是通过one-to-one 元 ... -
HIbernate主键生成策略详解 (转)
2012-03-04 13:39 1714HIberna ... -
hibernate 复习 单向一对一的实现
2012-03-03 15:38 1420hibernate中单向一对一实现有三种方式:主键关联, ... -
hibernate 复习--demo
2012-03-02 20:40 1528今天晚上,搞好了hibernate的demo了,明天开始就是搞 ... -
HibernateDaoSupport与JdbcDaoSupport
2011-12-30 07:38 16792011年11月07日 星期一 ... -
hibernage getcurrentsession
2011-12-28 18:56 1558org.hibernate.Hibe ... -
hibernate开发资料学习资料
2011-12-28 07:42 1513http://dev.21tx.com/java/struts ... -
hibernate one to many lazy 常见错误解决
2011-06-26 20:17 2580解释一个关于Hibernate l ... -
hibernate的增删改查
2011-06-25 22:03 1811package com.endual.test; impor ... -
frameset
2011-05-25 09:43 1057<a href=url target=_blank> ... -
Hibernate+Spring+Struts2+ExtJS开发CRUD功能
2011-05-17 08:56 4813http://blog.csdn.net/myloon/arc ...
相关推荐
此代码主要是用JDBC和MySQL数据库完成一个简单的用户管理系统,系统的设计模式采用工场模 式和代 理模式,此代码很适合初学Java者。 运行方法: 1.运行需要启动MySQL数据库 2.创建数据库名为zhaochao和表名为...
String sql = "INSERT INTO wp_posts ( post_date )VALUES(?)"; PreparedStatement pstmt = connection.prepareStatement(sql); Timestamp time = new Timestamp(System.currentTimeMillis()); pstmt.set...
4.StringAndDate.java 字符串与时间对象的相互转换 5.JdbcConn.java java jdbc连接oracle/mysql 6.NioFile.java nio操作文件读写 7.ImageThumbnail.java 生成图片缩略图 8.JsonObjs.java json简单操作 9....
4.12.1 在 Win32 上安装 MySQL 4.12.2 在 Win95 /Win98上启动 MySQL 4.12.3 在 NT 上启动 MySQL 4.12.4 在 Win32 上运行 MySQL 4.12.5 用 SSH 从 Win32 连接一个远程MySQL 4.12.6 MySQL-Win...
# 7.3.6.2 DATETIME,DATE和TIMESTAMP类型 # 7.3.6.3 TIME类型 # 7.3.6.4 YEAR类型 + 7.3.7 字符串类型 # 7.3.7.1 CHAR和VARCHAR类型 # 7.3.7.2 BLOB和TEXT类型 # 7.3.7.3 ENUM类型 # 7.3.7.4 SET类型 + ...
MySQL中文参考手册.chm 449kb <br/>0 译者序 1 MySQL的一般的信息 1.1 什么是MySQL? 1.2 关于本手册 1.2.1 本手册中使用的约定 1.3 MySQL的历史 1.4 MySQL的主要特征 1.5...
import java.sql.*; import java.text.DateFormat;... String dbUrl="jdbc:mysql://localhost:3306/sss";//根据实际情况变化 String username="root"; String password="123"; public Connection getConn() { Conn
public static int InsertReader(String name,String sex,String age,String identityCard,Date date,String maxNum,String tel,Double keepMoney,String zj,String zy,Date bztime,String ISBN){ int i=0; try...
11.3.1. DATETIME、DATE和TIMESTAMP类型 11.3.2. TIME类型 11.3.3. YEAR类型 11.3.4. Y2K事宜和日期类型 11.4. String类型 11.4.1. CHAR和VARCHAR类型 11.4.2. BINARY和VARBINARY类型 11.4.3. BLOB和TEXT类型 11.4.4...
11.3.1. DATETIME、DATE和TIMESTAMP类型 11.3.2. TIME类型 11.3.3. YEAR类型 11.3.4. Y2K事宜和日期类型 11.4. String类型 11.4.1. CHAR和VARCHAR类型 11.4.2. BINARY和VARBINARY类型 11.4.3. BLOB和TEXT类型 11.4.4...
DATETIME、DATE和TIMESTAMP类型 11.3.2. TIME类型 11.3.3. YEAR类型 11.3.4. Y2K事宜和日期类型 11.4. String类型 11.4.1. CHAR和VARCHAR类型 11.4.2. BINARY和VARBINARY类型 11.4.3. BLOB和...
11.3.1. DATETIME、DATE和TIMESTAMP类型 11.3.2. TIME类型 11.3.3. YEAR类型 11.3.4. Y2K事宜和日期类型 11.4. String类型 11.4.1. CHAR和VARCHAR类型 11.4.2. BINARY和VARBINARY类型 11.4.3. BLOB和TEXT类型 ...
11.3.1. DATETIME、DATE和TIMESTAMP类型 11.3.2. TIME类型 11.3.3. YEAR类型 11.3.4. Y2K事宜和日期类型 11.4. String类型 11.4.1. CHAR和VARCHAR类型 11.4.2. BINARY和VARBINARY类型 11.4.3. BLOB和TEXT类型 11.4.4...
11.3.1. DATETIME、DATE和TIMESTAMP类型 11.3.2. TIME类型 11.3.3. YEAR类型 11.3.4. Y2K事宜和日期类型 11.4. String类型 11.4.1. CHAR和VARCHAR类型 11.4.2. BINARY和VARBINARY类型 11.4.3. BLOB和TEXT类型 11.4.4...
11.3.1. DATETIME、DATE和TIMESTAMP类型 11.3.2. TIME类型 11.3.3. YEAR类型 11.3.4. Y2K事宜和日期类型 11.4. String类型 11.4.1. CHAR和VARCHAR类型 11.4.2. BINARY和VARBINARY类型 11.4.3. BLOB和TEXT类型...
031105_【第11章:Java常用类库】_日期操作类(Date、Calendar)笔记.pdf 031106_【第11章:Java常用类库】_日期操作类(DateFormat、SimpleDateFormat)笔记.pdf 031107_〖第11章:Java常用类库〗_实例操作:取得...
mysql,jdbc,Hibernate,tomcat [mysql+jdbc+jsp+Hibernate3.2+tomcattomcat5.028成功测试-简单] <br> 1 .数据库设计:库mydb 表events <br>EVENT_ID BIGINT(20) NOT NULL AUTOINC EVENT_DATE DATETIME...
Using MySQL Stored Programs with Java Section 14.1. Review of JDBC Basics Section 14.2. Using Stored Programs in JDBC Section 14.3. Stored Programs and J2EE Applications Section 14.4. Using ...
11.3.1. DATETIME、DATE和TIMESTAMP类型 11.3.2. TIME类型 11.3.3. YEAR类型 11.3.4. Y2K事宜和日期类型 11.4. String类型 11.4.1. CHAR和VARCHAR类型 11.4.2. BINARY和VARBINARY类型 11.4.3. BLOB和TEXT类型 11.4.4...