TestTime

import java.io.PrintStream;

import java.text.DateFormat;

import java.text.ParsePosition;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Date;

import java.util.GregorianCalendar;

public class TestTime {

private int weeks = 0;

private int MaxDate;

private int MaxYear;

public static void main(String[] paramArrayOfString)   {

TestTime localTestTime = new TestTime();

System.out.println("获取当天日期:" + localTestTime.getNowTime("yyyy-MM-dd"));

System.out.println("获取本周一日期:" + localTestTime.getMondayOFWeek());

System.out.println("获取本周日的日期~:" + localTestTime.getCurrentWeekday());

System.out.println("获取上周一日期:" + localTestTime.getPreviousWeekday());

System.out.println("获取上周日日期:" + localTestTime.getPreviousWeekSunday());

System.out.println("获取下周一日期:" + localTestTime.getNextMonday());

System.out.println("获取下周日日期:" + localTestTime.getNextSunday());

System.out.println("获得相应周的周六的日期:" + localTestTime.getNowTime("yyyy-MM-dd"));

System.out.println("获取本月第一天日期:" + localTestTime.getFirstDayOfMonth());

System.out.println("获取本月最后一天日期:" + localTestTime.getDefaultDay());

System.out.println("获取上月第一天日期:" + localTestTime.getPreviousMonthFirst());

System.out.println("获取上月最后一天的日期:" + localTestTime.getPreviousMonthEnd());

System.out.println("获取下月第一天日期:" + localTestTime.getNextMonthFirst());

System.out.println("获取下月最后一天日期:" + localTestTime.getNextMonthEnd());

System.out.println("获取本年的第一天日期:" + localTestTime.getCurrentYearFirst());

System.out.println("获取本年最后一天日期:" + localTestTime.getCurrentYearEnd());

System.out.println("获取去年的第一天日期:" + localTestTime.getPreviousYearFirst());

System.out.println("获取去年的最后一天日期:" + localTestTime.getPreviousYearEnd());

System.out.println("获取明年第一天日期:" + localTestTime.getNextYearFirst());

System.out.println("获取明年最后一天日期:" + localTestTime.getNextYearEnd());

System.out.println("获取本季度第一天到最后一天:" + localTestTime.getThisSeasonTime(11));

System.out.println("获取两个日期之间间隔天数2008-12-1~2008-9.29:" + getTwoDay("2008-12-1", "2008-9-29"));   }

public static String getTwoDay(String paramString1, String paramString2)   {

SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

long l = 0L;

try {

Date localDate1 = localSimpleDateFormat.parse(paramString1);

Date localDate2 = localSimpleDateFormat.parse(paramString2);

l = (localDate1.getTime() - localDate2.getTime()) / 86400000L;

} catch (Exception localException) {

return "";

}     return l + "";

}

public static String getWeek(String paramString)   {

Date localDate = strToDate(paramString);

Calendar localCalendar = Calendar.getInstance();

localCalendar.setTime(localDate);

return new SimpleDateFormat("EEEE").format(localCalendar.getTime());

}

public static Date strToDate(String paramString)   {

SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

ParsePosition localParsePosition = new ParsePosition(0);

Date localDate = localSimpleDateFormat.parse(paramString, localParsePosition);

return localDate;

}

public static long getDays(String paramString1, String paramString2)   {

if ((paramString1 == null) || (paramString1.equals("")))       return 0L;

if ((paramString2 == null) || (paramString2.equals(""))) {       return 0L;     }

SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

Date localDate1 = null;     Date localDate2 = null;

try {

localDate1 = localSimpleDateFormat.parse(paramString1);

localDate2 = localSimpleDateFormat.parse(paramString2);

} catch (Exception localException) {

}     long l = (localDate1.getTime() - localDate2.getTime()) / 86400000L;     return l;   }

public String getDefaultDay()   {

String str = "";

SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

Calendar localCalendar = Calendar.getInstance();

localCalendar.set(5, 1);

localCalendar.add(2, 1);

localCalendar.add(5, -1);

str = localSimpleDateFormat.format(localCalendar.getTime());     return str;   }

public String getPreviousMonthFirst()   {

String str = "";

SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

Calendar localCalendar = Calendar.getInstance();     localCalendar.set(5, 1);     localCalendar.add(2, -1);

str = localSimpleDateFormat.format(localCalendar.getTime());     return str;   }

public String getFirstDayOfMonth()   {     String str = "";     SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

Calendar localCalendar = Calendar.getInstance();     localCalendar.set(5, 1);     str = localSimpleDateFormat.format(localCalendar.getTime());     return str;   }

public String getCurrentWeekday()   {     this.weeks = 0;     int i = getMondayPlus();     GregorianCalendar localGregorianCalendar = new GregorianCalendar();     localGregorianCalendar.add(5, i + 6);     Date localDate = localGregorianCalendar.getTime();

DateFormat localDateFormat = DateFormat.getDateInstance();     String str = localDateFormat.format(localDate);     return str;   }

public String getNowTime(String paramString)   {     Date localDate = new Date();     SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat(paramString);     String str = localSimpleDateFormat.format(localDate);     return str;   }

private int getMondayPlus()   {     Calendar localCalendar = Calendar.getInstance();

int i = localCalendar.get(7) - 1;     if (i == 1) {       return 0;     }     return 1 - i;   }

public String getMondayOFWeek()   {     this.weeks = 0;     int i = getMondayPlus();     GregorianCalendar localGregorianCalendar = new GregorianCalendar();     localGregorianCalendar.add(5, i);     Date localDate = localGregorianCalendar.getTime();

DateFormat localDateFormat = DateFormat.getDateInstance();     String str = localDateFormat.format(localDate);     return str;   }

public String getSaturday()   {     int i = getMondayPlus();     GregorianCalendar localGregorianCalendar = new GregorianCalendar();     localGregorianCalendar.add(5, i + 7 * this.weeks + 6);     Date localDate = localGregorianCalendar.getTime();     DateFormat localDateFormat = DateFormat.getDateInstance();     String str = localDateFormat.format(localDate);     return str;   }

public String getPreviousWeekSunday()   {     this.weeks = 0;     this.weeks -= 1;     int i = getMondayPlus();     GregorianCalendar localGregorianCalendar = new GregorianCalendar();     localGregorianCalendar.add(5, i + this.weeks);     Date localDate = localGregorianCalendar.getTime();     DateFormat localDateFormat = DateFormat.getDateInstance();     String str = localDateFormat.format(localDate);     return str;   }

public String getPreviousWeekday()   {     this.weeks -= 1;     int i = getMondayPlus();     GregorianCalendar localGregorianCalendar = new GregorianCalendar();     localGregorianCalendar.add(5, i + 7 * this.weeks);     Date localDate = localGregorianCalendar.getTime();     DateFormat localDateFormat = DateFormat.getDateInstance();     String str = localDateFormat.format(localDate);     return str;   }

public String getNextMonday()   {     this.weeks += 1;     int i = getMondayPlus();     GregorianCalendar localGregorianCalendar = new GregorianCalendar();     localGregorianCalendar.add(5, i + 7);     Date localDate = localGregorianCalendar.getTime();     DateFormat localDateFormat = DateFormat.getDateInstance();     String str = localDateFormat.format(localDate);     return str;   }

public String getNextSunday()   {     int i = getMondayPlus();     GregorianCalendar localGregorianCalendar = new GregorianCalendar();     localGregorianCalendar.add(5, i + 7 + 6);     Date localDate = localGregorianCalendar.getTime();     DateFormat localDateFormat = DateFormat.getDateInstance();     String str = localDateFormat.format(localDate);     return str;   }

private int getMonthPlus()   {     Calendar localCalendar = Calendar.getInstance();     int i = localCalendar.get(5);     localCalendar.set(5, 1);     localCalendar.roll(5, -1);     this.MaxDate = localCalendar.get(5);     if (i == 1) {       return -this.MaxDate;     }     return 1 - i;   }

public String getPreviousMonthEnd()   {     String str = "";     SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

Calendar localCalendar = Calendar.getInstance();     localCalendar.add(2, -1);     localCalendar.set(5, 1);     localCalendar.roll(5, -1);     str = localSimpleDateFormat.format(localCalendar.getTime());     return str;   }

public String getNextMonthFirst()   {     String str = "";     SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

Calendar localCalendar = Calendar.getInstance();     localCalendar.add(2, 1);     localCalendar.set(5, 1);     str = localSimpleDateFormat.format(localCalendar.getTime());     return str;   }

public String getNextMonthEnd()   {     String str = "";     SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

Calendar localCalendar = Calendar.getInstance();     localCalendar.add(2, 1);     localCalendar.set(5, 1);     localCalendar.roll(5, -1);     str = localSimpleDateFormat.format(localCalendar.getTime());     return str;   }

public String getNextYearEnd()   {     String str = "";     SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

Calendar localCalendar = Calendar.getInstance();     localCalendar.add(1, 1);     localCalendar.set(6, 1);     localCalendar.roll(6, -1);     str = localSimpleDateFormat.format(localCalendar.getTime());     return str;   }

public String getNextYearFirst()   {     String str = "";     SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

Calendar localCalendar = Calendar.getInstance();     localCalendar.add(1, 1);     localCalendar.set(6, 1);     str = localSimpleDateFormat.format(localCalendar.getTime());     return str;   }

private int getMaxYear()   {     Calendar localCalendar = Calendar.getInstance();     localCalendar.set(6, 1);     localCalendar.roll(6, -1);     int i = localCalendar.get(6);     return i;   }

private int getYearPlus() {     Calendar localCalendar = Calendar.getInstance();     int i = localCalendar.get(6);     localCalendar.set(6, 1);     localCalendar.roll(6, -1);     int j = localCalendar.get(6);     if (i == 1) {       return -j;     }     return 1 - i;   }

public String getCurrentYearFirst()   {     int i = getYearPlus();     GregorianCalendar localGregorianCalendar = new GregorianCalendar();     localGregorianCalendar.add(5, i);     Date localDate = localGregorianCalendar.getTime();     DateFormat localDateFormat = DateFormat.getDateInstance();     String str = localDateFormat.format(localDate);     return str;   }

public String getCurrentYearEnd()   {     Date localDate = new Date();     SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy");     String str = localSimpleDateFormat.format(localDate);     return str + "-12-31";   }

public String getPreviousYearFirst()   {     Date localDate = new Date();     SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy");     String str = localSimpleDateFormat.format(localDate); int i = Integer.parseInt(str);     i--;     return i + "-1-1";   }

public String getPreviousYearEnd()   {     this.weeks -= 1;     int i = getYearPlus();     GregorianCalendar localGregorianCalendar = new GregorianCalendar();     localGregorianCalendar.add(5, i + this.MaxYear * this.weeks + (this.MaxYear - 1));     Date localDate = localGregorianCalendar.getTime();     DateFormat localDateFormat = DateFormat.getDateInstance();     String str = localDateFormat.format(localDate);     getThisSeasonTime(11);     return str;   }

public String getThisSeasonTime(int paramInt)   {     int[][] arrayOfInt = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }, { 10, 11, 12 } };     int i = 1;     if ((paramInt >= 1) && (paramInt <= 3)) {       i = 1;     }     if ((paramInt >= 4) && (paramInt <= 6)) {       i = 2;     }     if ((paramInt >= 7) && (paramInt <= 9)) {       i = 3;     }     if ((paramInt >= 10) && (paramInt <= 12)) {       i = 4;     }     int j = arrayOfInt[(i - 1)][0];     int k = arrayOfInt[(i - 1)][2];

Date localDate = new Date();     SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy");     String str1 = localSimpleDateFormat.format(localDate);     int m = Integer.parseInt(str1);

int n = 1;     int i1 = getLastDayOfMonth(m, k);     String str2 = m + "-" + j + "-" + n + ";" + m + "-" + k + "-" + i1;     return str2;   }

private int getLastDayOfMonth(int paramInt1, int paramInt2)   {     if ((paramInt2 == 1) || (paramInt2 == 3) || (paramInt2 == 5) || (paramInt2 == 7) || (paramInt2 == 8) || (paramInt2 == 10) || (paramInt2 == 12))     {       return 31;     }     if ((paramInt2 == 4) || (paramInt2 == 6) || (paramInt2 == 9) || (paramInt2 == 11)) {       return 30;     }     if (paramInt2 == 2) {       if (isLeapYear(paramInt1)) {         return 29;       }       return 28;     }

return 0;   }

public boolean isLeapYear(int paramInt)   {     return ((paramInt % 4 == 0) && (paramInt % 100 != 0)) || (paramInt % 400 == 0);   } }

时间: 2024-10-09 23:03:58

TestTime的相关文章

layers.py cs231n

如果有错误,欢迎指出,不胜感激. import numpy as np def affine_forward(x, w, b): 第一个最简单的 affine_forward简单的前向传递,返回 out,cache """ Computes the forward pass for an affine (fully-connected) layer. The input x has shape (N, d_1, ..., d_k) and contains a minibat

软件工程实验一 复利计算——单元测试

对复利计算器进行单元测试 一.实验历次题目要求 1.客户说:帮我开发一个复利计算软件. 2.如果按照单利计算,本息又是多少呢? 3.假如30年之后要筹措到300万元的养老金,平均的年回报率是3%,那么,现在必须投入的本金是多少呢? 4.利率这么低,复利计算收益都这么厉害了,如果拿100万元去买年报酬率10%的股票,若一切顺利,过多长时间,100万元就变成200万元呢? 5.如果我希望在十年内将100万元变成200万元,应该找到报酬率在多少的投资工具来帮助我达成目标?如果想在5年后本金翻倍,报酬率

【Java 语言生态篇】Junit 测试单元

01 概述 JUnit是一个由 Erich Gamma 和 Kent Beck 编写的一个回归测试框架(regression testing framework).Junit测试是白盒测试.JUnit有它自己的JUnit扩展生态圈.多数Java的开发环境都已经集成了JUnit作为单元测试的工具.[1] JUnit是一个开放源代码的Java测试框架,用于编写和运行可重复的测试.他是用于单元测试框架体系xUnit的一个实例(用于java语言).它包括以下特性: 1.用于测试期望结果的断言(Asser

Junit安装及使用

Eclipse中已经对JUnit做了集成,可见其重要性,下面简单介绍一下在Eclipse中使用JUnit 4对加减乘除进行测试. 1.新建工程,写出加减乘除的代码,命名为Calculate类,需要对其进行测试 1 public class Calculate { 2 3 public int add(int x, int y){ 4 return x + y; 5 } 6 public int minus(int x, int y){ 7 return x - y; 8 } 9 public i

Java回调函数详解

为了了解什么是回调函数,在网上查阅了如下资料,整理如下: 资料一: 首先说说什么叫回调函数? 在WINDOWS中,程序员想让系统DLL调用自己编写的一个方法,于是利用DLL当中回调函数(CALLBACK)的接口来编写程序,使它调用,这个就 称为回调.在调用接口时,需要严格的按照定义的参数和方法调用,并且需要处理函数的异步,否则会导致程序的崩溃. 这样的解释似乎还是比较难懂,这里举个简 单的例子: 程序员A写了一段程序(程序a),其中预留有回调函数接口,并封装好了该程序.程序员B要让a调用自己的程

奇怪的SQLserver执行

今天工作遇到,下面这段执行超慢,几乎不出来,在旧服务器上运行是可以的,一样代码,很快,在新虚拟服务器上,超慢. select * from ( select RowNum=row_number() over(order by AutoId desc),StartTime,cast(testtime/1000.00 as decimal(10,2)) as testtime,AutoId from dbo.FTMaster M WITH(NOLock) Where StartTime >='201

Unity3D-简单的倒计时

using UnityEngine; using System.Collections; using System; /* * 用法:新建一个场景,新建一个3D Text,把该3D Text的Transform重置一下,给它添加该脚本,运行即可 */ public class TestTime : MonoBehaviour { private int currentPower = 5;//当前体力值 private int maxPower = 10;//最大体力值 private int p

Chapter7: question 49 - 50

49. 把字符串转换为整数 很多细节需要注意.(空格,符号,溢出等) Go: 8. String to Integer (atoi) 50. 树种两个结点的最低公共祖先 A. 若是二叉搜索树,直接与根结点对比. 若都大于根节点,则在友子树:若都小于根节点,则在左子树:若根节点介于两数之间,则根节点即为答案. B. 普通树,若是孩子节点有指向父节点的指针,则问题变为求两个链表的第一个公共结点. 如:37题. C. 普通树:思路1,若一个结点的子树同时包含两个结点,而它的任一孩子结点的子树却不能同时

设计模式实战应用之五:工厂方法模式

工厂方法模式的定义        工厂方法模式的应用相当广泛. 工厂方法模式在 Java API 中的应用比比皆是:java.util.Collection 接口的 iterator 方法就是一个非常著名的工厂方法模式的演示样例:java.net.URLStreamHandlerFactory 的 createURLStreamHandler(String protocol)  也是工厂方法模式的一个非常经典的应用,URLStreamHandlerFactory 定义了一个用来创建 URLStr