-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
加入Joda-Time,并实现时间公共类,后期根据需要可以在TimeUtil类中继续拓展
- Loading branch information
Showing
9 changed files
with
90 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/web/CaptchaController.java → ...main/java/kcaptcha/CaptchaController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package util.DateTime; | ||
|
||
import org.joda.time.DateTime; | ||
import org.joda.time.LocalDate; | ||
|
||
/** | ||
* Created by xuweijie on 2017/3/8. | ||
* 日期公共类,单例模式(双重检查加锁,可以大大减少getInstance()的同步问题所带来的时间耗费) | ||
*/ | ||
public class TimeUtil { | ||
|
||
private volatile static TimeUtil timeUtil; | ||
private DateTime dateTime; | ||
|
||
public static TimeUtil getInstance(){ | ||
if(timeUtil==null){ | ||
synchronized (TimeUtil.class){ | ||
if(timeUtil==null){ | ||
timeUtil=new TimeUtil(); | ||
} | ||
} | ||
} | ||
return timeUtil; | ||
} | ||
|
||
//自定义表示的某个时刻的时间(具体到时分秒) | ||
public String GetTimeAtPoin(int year,int month,int day,int hour,int min,int sec){ | ||
dateTime=new DateTime(year,month,day,hour,min,sec); | ||
return dateTime.toString("yyyy/MM/dd HH:mm:ss EE"); | ||
} | ||
|
||
public String GetTimeAtPoin(int year,int month,int day){ | ||
dateTime=new DateTime(year,month,day,0,0,0); | ||
return dateTime.toString("yyyy/MM/dd EE"); | ||
} | ||
|
||
//在某个日期上加上xx天(如:在当前日期加上90天)(具体到时分秒) | ||
public String GetTimeAtPoin(int year,int month,int day,int hour,int min,int sec,int additionalTime){ | ||
dateTime=new DateTime(year,month,day,hour,min,sec); | ||
return dateTime.plusDays(additionalTime).toString("yyyy/MM/dd HH:mm:ss EE"); | ||
} | ||
|
||
public String GetTimeAtPoin(int year,int month,int day,int additionalTime){ | ||
dateTime=new DateTime(year,month,day,0,0,0); | ||
return dateTime.plusDays(additionalTime).toString("yyyy/MM/dd EE"); | ||
} | ||
|
||
|
||
//获取当前时间 | ||
public String CurrentTime(){ | ||
return dateTime.toString("yyyy/MM/dd HH:mm:ss EE"); | ||
} | ||
|
||
} |
3 changes: 2 additions & 1 deletion
3
src/main/java/util/MD5Util.java → src/main/java/util/Encryption/MD5Util.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import org.joda.time.DateTime; | ||
import org.junit.Test; | ||
import util.DateTime.TimeUtil; | ||
|
||
/** | ||
* Created by xuweijie on 2017/3/8. | ||
*/ | ||
public class timetest { | ||
|
||
@Test | ||
public void testtime(){ | ||
|
||
String time=TimeUtil.getInstance().GetTimeAtPoin(2017,3,8,23,33,56); | ||
System.out.println("某一时刻的时间:"+time); | ||
String currenttime=TimeUtil.getInstance().CurrentTime(); | ||
System.out.println("当前时间:"+currenttime); | ||
String addtime=TimeUtil.getInstance().GetTimeAtPoin(2017,3,8,23,33,56,90); | ||
System.out.println("某一时刻的时间+加上90天:"+addtime); | ||
String time1=TimeUtil.getInstance().GetTimeAtPoin(2017,3,8); | ||
System.out.println("某一时刻的时间:"+time1); | ||
|
||
} | ||
} |