时间计算器
public Date calculateDate ( Date date, Integer number) {
Calendar rightNow = Calendar . getInstance ( ) ;
rightNow. setTime ( date) ;
rightNow. add ( Calendar . YEAR, - 1 ) ;
rightNow. add ( Calendar . MONTH, 3 ) ;
rightNow. add ( Calendar . DAY_OF_YEAR, 10 ) ;
rightNow. add ( Calendar . SECOND, 60 ) ;
Date dt= rightNow. getTime ( ) ;
System . out. println ( dd. format ( dt) ) ;
return dt;
}
SimpleDateFormat ddHHmm = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss" ) ;
Date date2 = new Date ( ) ;
System . out. println ( ddHHmm. format ( date2) ) ;
Date比较
String beginTime = "2018-07-28 14:42:32" ;
String endTime = "2018-07-29 12:26:32" ;
SimpleDateFormat format = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss" ) ;
Date date1 = format. parse ( beginTime) ;
Date date2 = format. parse ( endTime) ;
int compareTo = date1. compareTo ( date2) ;
获取上月或本月的第一天或最后一天
SimpleDateFormat format = new SimpleDateFormat ( "yyyy-MM-dd" ) ;
Calendar cal_1= Calendar . getInstance ( ) ;
cal_1. add ( Calendar . MONTH, - 1 ) ;
cal_1. set ( Calendar . DAY_OF_MONTH, 1 ) ;
System . out. println ( "上月第一天:" + format. format ( cal_1. getTime ( ) ) ) ;
Calendar cale = Calendar . getInstance ( ) ;
cale. set ( Calendar . DAY_OF_MONTH, 0 ) ;
System . out. println ( "上月最后一天:" + format. format ( cale. getTime ( ) ) ) ;
Calendar c = Calendar . getInstance ( ) ;
c. add ( Calendar . MONTH, 0 ) ;
c. set ( Calendar . DAY_OF_MONTH, 1 ) ;
String first = format. format ( c. getTime ( ) ) ;
System . out. println ( "当前月第一天:" + first) ;
Calendar ca = Calendar . getInstance ( ) ;
ca. set ( Calendar . DAY_OF_MONTH, ca. getActualMaximum ( Calendar . DAY_OF_MONTH) ) ;
String last = format. format ( ca. getTime ( ) ) ;
System . out. println ( "当前月最后一天:" + last) ;
SqlServer转移/备份表数据
SELECT * INTO em_settlement_bf FROM em_settlement;
insert into 表1 ( 字段1 ,字段2 ,字段3 ) select 字段1 ,字段2 ,字段3 from 表2
insert into SYS_TASK_ITTASK ( fd_itsystem) select fd_sys_id from ISSUE_MAIN;
判断字符串是否为整数
public static boolean isInteger ( String str) {
Pattern pattern = Pattern . compile ( "^[-\\+]?[\\d]*$" ) ;
return pattern. matcher ( str) . matches ( ) ;
}
Sql Server 实现分页查询
select
COUNT ( * ) OVER ( PARTITION BY '' ) AS Total,
fd_engineCode
from em_project_detail
order by fd_id
offset ( ( 1 - 1 ) * 15 ) rows
fetch next 15 rows only
Java 小数位四舍五入函数
Math 类中提供了5 个与取整相关的函数,如下所示:
static double ceil ( double a) :天花板函数,返回大于等于a的最小整数(但是以浮点数形式存储)。
static double floor ( double a) :地板函数,返回小于等于a的最大整数(但是以浮点数形式存储)。
static double rint ( double a) :四舍五入函数,返回与a的值最相近的整数(但是以浮点数形式存储)。
static long round ( double a) :四舍五入函数,返回与a的值最相近的长整型数。
static int round ( float a) :四舍五入函数,返回与a的值最相近的整型数。
修改字段长度
alter table 表名 alter column 字段名 数据类型( 长度)
保留两位小数
DecimalFormat df = new DecimalFormat ( "00.##" ) ;
Double . parseDouble ( df. format ( 0.1459 ) ;
String . format ( "%.2f" , 数字) ;
加法
public static BigDecimal add ( BigDecimal . . . param) {
BigDecimal sumAdd = BigDecimal . valueOf ( 0 ) ;
for ( int i = 0 ; i < param. length; i++ ) {
BigDecimal bigDecimal = param[ i] == null ? new BigDecimal ( 0 ) : param[ i] ;
sumAdd = sumAdd. add ( bigDecimal) ;
}
return sumAdd;
}
减法
public static BigDecimal subtract ( BigDecimal . . . param) {
BigDecimal sumLess = param[ 0 ] ;
if ( sumLess == null ) return new BigDecimal ( 0 ) ;
for ( int i = 1 ; i < param. length; i++ ) {
BigDecimal bigDecimal = param[ i] == null ? new BigDecimal ( 0 ) : param[ i] ;
sumLess = sumLess. subtract ( bigDecimal) ;
}
return sumLess;
}
乘法
public static BigDecimal multiply ( BigDecimal first, BigDecimal last) {
if ( first == null ) first = new BigDecimal ( 0 ) ;
if ( last == null ) last = new BigDecimal ( 0 ) ;
return first. multiply ( last) . setScale ( 2 , BigDecimal . ROUND_HALF_UP) ;
}
除法
public static BigDecimal divide ( BigDecimal first, BigDecimal last) {
if ( first == null ) first = new BigDecimal ( 0 ) ;
if ( last == null ) last = new BigDecimal ( 0 ) ;
return first. divide ( last) . setScale ( 2 , BigDecimal . ROUND_HALF_UP) ;
}
判空
public static boolean isNotEmpty ( BigDecimal param) {
if ( ObjectUtil . isNotEmpty ( param) ) return true ;
return false ;
}
public static boolean isEmpty ( BigDecimal param) {
if ( ObjectUtil . isEmpty ( param) ) return true ;
return false ;
}
类源码
package com. common. utils ;
import cn. hutool. core. util. ObjectUtil ;
import java. math. BigDecimal ;
public class BigDecimalUtils {
public static BigDecimal add ( BigDecimal . . . param) {
BigDecimal sumAdd = BigDecimal . valueOf ( 0 ) ;
for ( int i = 0 ; i < param. length; i++ ) {
BigDecimal bigDecimal = param[ i] == null ? new BigDecimal ( 0 ) : param[ i] ;
sumAdd = sumAdd. add ( bigDecimal) ;
}
return sumAdd;
}
public static BigDecimal subtract ( BigDecimal . . . param) {
BigDecimal sumLess = param[ 0 ] ;
if ( sumLess == null ) return new BigDecimal ( 0 ) ;
for ( int i = 1 ; i < param. length; i++ ) {
BigDecimal bigDecimal = param[ i] == null ? new BigDecimal ( 0 ) : param[ i] ;
sumLess = sumLess. subtract ( bigDecimal) ;
}
return sumLess;
}
public static BigDecimal multiply ( BigDecimal first, BigDecimal last) {
if ( first == null ) first = new BigDecimal ( 0 ) ;
if ( last == null ) last = new BigDecimal ( 0 ) ;
return first. multiply ( last) . setScale ( 2 , BigDecimal . ROUND_HALF_UP) ;
}
public static BigDecimal divide ( BigDecimal first, BigDecimal last) {
if ( first == null ) first = new BigDecimal ( 0 ) ;
if ( last == null ) last = new BigDecimal ( 0 ) ;
return first. divide ( last) . setScale ( 2 , BigDecimal . ROUND_HALF_UP) ;
}
public static boolean isNotEmpty ( BigDecimal param) {
if ( ObjectUtil . isNotEmpty ( param) ) return true ;
return false ;
}
public static boolean isEmpty ( BigDecimal param) {
if ( ObjectUtil . isEmpty ( param) ) return true ;
return false ;
}
}
JS获取单选框的值有三种方式:
1 、$ ( 'input:radio:checked' ) . val ( ) ;
2 、$ ( "input[type='radio']:checked" ) . val ( ) ;
3 、$ ( "input[name='rd']:checked" ) . val ( ) ;
js的Double类型数字比较
if ( eval ( 数字1 ) >= eval ( 数字2 ) ) { }