- 浏览: 412150 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (239)
- java (59)
- JQuery (5)
- oracle (12)
- javascript (14)
- struts1 (1)
- spring (10)
- Quartz (2)
- ibatis (1)
- linux (32)
- weblogic (3)
- ibaits (2)
- servlet (1)
- log4j (5)
- 编程人生 (2)
- apache (3)
- window (3)
- web前端 (25)
- 错误集合 (2)
- 框架配置 (1)
- 开发工具 (15)
- 小插件应用 (1)
- lucene (1)
- sonar (1)
- velocity (1)
- 代码检查 (0)
- error (1)
- jndi (1)
- oracle函数 (1)
- tools (1)
- 代码管理 (3)
- mysql (4)
- maven (9)
- bat (1)
- git (3)
- aix (2)
- freemarker (1)
- svn (2)
- nginx (6)
最新评论
-
masuweng:
f
修改eclipse的内存 -
洞渊龙王:
...
maven-surefire-plugin学习 -
phf717601206:
WEB-INF/lib下就没有servlet-api.jar ...
Unable to read TLD "META-INF/c.tld"错误 -
sziitjiang:
很好,非常不错
Java读写excel之poi -
dengminghua1016:
doris1bruce 写道一、二、 ...
java创建对象的几种方式
/**
* 此文件描述的是:常用工具转换类
*/
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.text.DateFormat;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
/**
* @author blaiu
*
*/
public class Common {
/**
* 此类描述的是:字符串与时间类型的转换
* @param date
* @return String类型,格式为:yyyy年MM月dd日 星期EEE HH时mm分ss秒
*/
public static String getStr1(Date date) {
DateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 星期EEE HH时mm分ss秒");
String timeStr = dateFormat.format(date);
return timeStr;
}
public static String getStrShort(Date date) {
DateFormat dateFormat = new SimpleDateFormat("MM-dd");
String timeStr = dateFormat.format(date);
return timeStr;
}
/**
* 此类描述的是:字符串与时间类型的转换
* @param date
* @return String类型,格式为:yyyyMM
*/
public static String getStr2() {
Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("yyyyMM");
String timeStr = dateFormat.format(date);
return timeStr;
}
/**
* 此类描述的是:字符串与时间类型的转换
* @param date
* @return String类型,格式为:yyyy-MM-dd
*/
public static String getStr(Date date) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String timeStr = dateFormat.format(date);
return timeStr;
}
/**
* 此类描述的是:字符串与时间类型的转换
* @param time
* @return String类型,格式为:yyyy-MM-dd HH:mm:ss
*/
public static String getStr2(Date date) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String timeStr = dateFormat.format(date);
return timeStr;
}
/**
* 此类描述的是:字符串与时间类型的转换
* @param str
* @return Date类型,格式为:yyyy-MM-dd
*/
public static Date getDateShort(String str) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
ParsePosition pos = new ParsePosition(0);
Date formatDate = dateFormat.parse(str, pos);
return formatDate;
}
/**
* 此类描述的是:字符串与时间类型的转换
* @param str
* @return Date类型,格式为:yyyy-MM-dd HH:mm:ss
*/
public static Date getDateFull(String str) {
if(null==str || "".equals(str)) {
return null;
} else {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ParsePosition pos = new ParsePosition(0);
Date formatDate = dateFormat.parse(str, pos);
System.out.println(formatDate.toString());
return formatDate;
}
}
/**
*
* @此方法描述的是:获得当前的时间 例如:Mon May 18 10:26:29 CST 2009
* @return
* Date
*/
public static Date getDate() {
Date date = new Date();
return date;
}
/**
*
* @此方法描述的是:获得当前的时间 例如:yyyy-MM-dd HH:mm:ss
* @return
* String
*/
public static String getFullTime() {
Calendar calendar = null;
SimpleDateFormat formatter = null;
calendar = new GregorianCalendar();
formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return formatter.format(calendar.getTime());
}
/**
* 对给定字符进行 URL 解码
*
* @param value
* String
* @return String
*/
public static String decode(String value) {
String result = "";
if (!isEmpty(value)) {
try {
result = java.net.URLDecoder.decode(value, "UTF-8");
result = java.net.URLDecoder.decode(result, "UTF-8");
} catch (UnsupportedEncodingException ex) {
}
}
return result;
}
/**
* 对给定字符进行 URL 编码
*
* @param value
* String
* @return String
*/
public static String encode(String value) {
String result = "";
if (!isEmpty(value)) {
try {
result = java.net.URLEncoder.encode(value, "UTF-8");
result = java.net.URLEncoder.encode(result, "UTF-8");
} catch (UnsupportedEncodingException ex) {
}
}
return result;
}
/**
* 判断是否为空,为空返回true
*
* @param value
* String
* @return boolean
*/
public static boolean isEmpty(String value) {
if (value == null || value.trim().equals("") || value.trim().equals("null")) {
return true;
} else {
return false;
}
}
/**
*
* 此方法描述的是:时间转换
* @param num
* @return
* String
*/
public static String getClosedDate(String num){
if(null==num || "".equals(num)) {
return null;
} else {
Calendar calendar = new GregorianCalendar();
SimpleDateFormat formatter = null;
formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if(num.equals("1")){
calendar.add(calendar.DAY_OF_YEAR, +1);
return formatter.format(calendar.getTime());
}else if(num.equals("2")){
calendar.add(calendar.DAY_OF_YEAR, +7);
return formatter.format(calendar.getTime());
}else if(num.equals("3")){
calendar.add(calendar.DAY_OF_YEAR, +30);
return formatter.format(calendar.getTime());
}else if(num.equals("4")){
calendar.add(calendar.MONTH, +3);
return formatter.format(calendar.getTime());
}else if(num.equals("5")){
calendar.add(calendar.MONTH, +6);
return formatter.format(calendar.getTime());
}else{
calendar.add(calendar.YEAR, +1);
return formatter.format(calendar.getTime());
}
}
}
public static String getWebInfPath(){
return new File(Common.class.getResource("/").getPath()).getParent();
}
public static String getUploadPath() {
return new File( new File( new File( new File(Common.class.getResource("/").getPath()).getParent()).getParent()).getParent()).getParent();
}
public static void main(String[] args) {
System.out.println(getWebInfPath());
}
}
发表评论
-
org.apache.catalina.util.DefaultAnnotationProcessor cannot be cast to org.ap解决方案
2014-05-09 09:24 806是tomcat的lib文件夹jar包和项目的lib文件下的j ... -
基于mock对象和JUnit框架简化Spring Web组件单元测试(1)
2014-03-13 14:25 1716对于Java组件开发者来说,他们都盼望拥有一组能够对组件开 ... -
org.apache.taglibs.standard 转换成javax.servlet.jsp.tagext异常
2014-02-23 14:29 916java.lang.ClassCastExceptio ... -
acegi源码分析
2014-02-17 11:42 699AbstractProcessi ... -
深入研究java.lang.ThreadLocal类
2014-02-13 14:19 438一、概述 ThreadLocal是什么呢?其实Thr ... -
java synchronized详解
2014-02-13 09:38 673Java语言的关键字,当它用来修饰一个方法或者一个代码块的时 ... -
如何使用ide打jar包以及如何在cmd运行jar包
2013-12-02 00:05 1049一、怎么打jar包 第一步:选中要打jar包的工程 第二 ... -
window下Java环境配置
2013-08-29 13:54 3691.打开我的电脑--属性--高级--环境变量 ... -
Unable to read TLD "META-INF/c.tld"错误
2013-08-12 17:50 14166严重: Servlet.service() for ser ... -
According to TLD or attribute directive in tag file, attribute value does not ac
2013-07-28 23:39 15656jsp编译的时候失败,原因是servlet版本与jstl标 ... -
使用velocity启动项目报错
2013-05-21 12:12 11126启动tomcat时,出现 2007-3-15 16:42 ... -
文件解压和压缩
2013-04-14 20:42 907文件解压和压缩 /** * compress ... -
java操作properties属性文件
2013-04-14 20:40 1086java更新或增加 ... -
JAVA基本数据类型
2013-04-11 11:30 0数据类型 大小 范围 ... -
JAVA应用 之 排序
2013-02-25 10:36 826概述: 1.本文阐述对List(Array乱入)的 ... -
JAVA基础 之 Map
2013-02-25 10:27 911概述: 1.键值对,key-value,具有映射关 ... -
JAVA基础 之 Collections
2013-02-25 10:24 1219概述: 1.Collec ... -
java基础之异常
2013-02-25 09:55 861讲述: 1.五个关键字 1.tr ... -
java实现缓存技术
2013-01-27 12:48 0java实现缓存技术,有时候我们需要将一些数据缓存起来,什么时 ... -
java创建对象的几种方式
2013-01-27 10:13 6304(1) 用new语句创建对象,这是最常见的创建对象的方法。 ...
相关推荐
工具类 基础的类型 对象 数据的工具,进行判断或者进行操作
java Maven中常用命令和插件java Maven中常用命令和插件java Maven中常用命令和插件java Maven中常用命令和插件java Maven中常用命令和插件java Maven中常用命令和插件java Maven中常用命令和插件java Maven中常用...
SpringBoot中常用的时间工具类使用
Java中常用类API.ppt
java开发中常用到的工具类。附有帮助文档。可以方便查看。如果需要源码的可以联系我。主要包括http-post请求工具类。日期工具类。字符串工具类。配置文件properties读取工具类。
java中常用的时间操作;如日期,时间戳,日历,字符串相互转化;时间差等常用日期功能。
Java中常量分类.pdf 学习资料 复习资料 教学资源
java字符串的处理,java中常用字符串方法总结,java中常用字符串方法总结,
JAVA中常用的数据结构,适用参加工作初期的Java开发者。
浅谈Java中常用数据结构的实现类Collection和Map共7页.pdf.zip
在日企得得朋友可以看看,........
Java中常用字符串方法总结
Java中常用的数据库连接方式有以下几种: JDBC(Java Database Connectivity): JDBC是Java提供的标准数据库连接API,可以与各种关系型数据库进行交互。JDBC提供了一组接口和类,用于连接数据库、执行SQL语句并...
MFC中常用类MFC中常用类MFC中常用类MFC中常用类MFC中常用类MFC中常用类MFC中常用类MFC中常用类MFC中常用类MFC中常用类MFC中常用类MFC中常用类MFC中常用类MFC中常用类MFC中常用类
在java中常出现的错误
Java中常用的数据库连接池[定义].pdf
java项目中常使用到的工具类:zip压缩解压缩、rar解压(有密码的文件)、gz解压、FTP上传与下载
对java常用命令java及javac做了深入介绍,以及这些命令在带包情况下的不同使用方式。
Android_SDK中常用命令行工具
一共84个jar包,java开发中常使用的,减少您网上搜索的时间