//整数相除 保留一位小数 public static String division(int a ,int b){ String result = ""; float num =(float)a/b; DecimalFormat df = new DecimalFormat("0.0"); result = df.format(num); return result; }…
平常总会遇到需要算两个日期之间是多少天,以下是使用JavaScript算时间差多少天的: // 给日期类对象添加日期差方法,返回日期与diff参数日期的时间差,单位为天 Date.prototype.diff = function(date){ return (this.getTime() - date.getTime())/(24 * 60 * 60 * 1000); } // 构造两个日期 var now = new Date('2015/03/01 12:43:45'); //也可以不要后…
function dateHanle(d1,d2){ if(Date.parse(d1) - Date.parse(d2)==0) { console.log("d1等于d2"); return 0; } if(Date.parse(d1) - Date.parse(d2)<0) { console.log("d1晚于d2"); return -1; } if(Date.parse(d1) - Date.parse(d2)>0) { console.lo…
方式1:被除数转double后,除以除数,结果是一个double类型的数,将double结果按要求保留n位小数即可. 保留n位小数的写法 int a = 10; int b = 3; double res = new BigDecimal((double) a / b).setScale(2, RoundingMode.HALF_UP).doubleValue(); 方式2: 直接使用BigDecimal进行运算 int a = 10; int b = 3; BigDecimal bigA =…
1.final关键字和.net中的const关键字一样,是常量的修饰符,但是final还可以修饰类.方法.写法规范:常量所有字母都大写,多个单词中间用 "_"连接. 2.遍历集合ArrayList<Integer> list = new ArrayList<Integer>();list.add(1);list.add(3);list.add(5);list.add(7);// 遍历List方法1,使用普通for循环:for (int i = 0; i <…
oracle 两个时间相减默认的是天数 oracle 两个时间相减默认的是天数*24 为相差的小时数 oracle 两个时间相减默认的是天数*24*60 为相差的分钟数 oracle 两个时间相减默认的是天数*24*60*60 为相差的秒数 --MONTHS_BETWEEN(date2,date1) 给出date2-date1的月份 SQL>  select months_between('19-12月-1999','19-3月-1999') mon_between from dual; MON…
原文地址:http://www.jb51.net/article/60177.htm using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test { class Program { static void Main(string[] args) { DateTime t1 = DateTime.Parse("2007-01-01"); DateT…
脚本之家看到的,关于两个时间差值的获取 http://www.jb51.net/article/60177.htm using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test { class Program { static void Main(string[] args) { DateTime t1 = DateTime.Parse("2007-01-0…
摘要: 下文讲述使用sql脚本实现相邻两条数据相减的方法,如下所示: 实验环境:sql server 2008 R2 实现思路: 1.使用cte表达式,对当前表进行重新编号 2.使用左连接对 表达式 生成的临时表进行错位连接,并对生成的新纪录中两列进行相减 ),qty int); go ----生成基础数据 insert into [maomao365](sort, qty)values (),(), (),(), (),() go with cte_temp as ( select row_n…