首页 文章 精选 留言 我的

精选列表

搜索[类],共10000篇文章
优秀的个人博客,低调大师

JAVA时间格式处理工具类

import java.text.DateFormat;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date; public class DateUtil { /** * 默认日期格式 */ public static String DEFAULT_FORMAT = "yyyy-MM-dd"; private static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); private static final SimpleDateFormat formatMs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.sss"); /** * 格式化日期 * @param date 日期对象 * @return String 日期字符串 */ public static String formatDate(Date date){ SimpleDateFormat f = new SimpleDateFormat(DEFAULT_FORMAT); String sDate = f.format(date); return sDate; } /** * 格式化日期 * @param str 日期对象 * @return String 日期字符串 */ public static Date formatDate(String str){ Date date = null; try{ SimpleDateFormat f = new SimpleDateFormat(DEFAULT_FORMAT); date = f.parse(str); }catch (Exception e){ e.printStackTrace(); } return date; } /** * 获取某年第一天日期 * @param date 账期 * @return Date */ public static String getYearFirst(String date){ Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(Calendar.YEAR, Integer.parseInt(date.substring(0, 4))); Date currYearFirst = calendar.getTime(); return formatDate(currYearFirst); } /** * 获取上年第一天日期 * @param date 账期 * @return Date */ public static String getLastYearFirst(String date){ Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(Calendar.YEAR, Integer.parseInt(date.substring(0, 4))); calendar.add(Calendar.YEAR, -1); Date currYearFirst = calendar.getTime(); return formatDate(currYearFirst); } /** * 获取某日的前一天日期 * @return Date */ public Date getDaysBefore(String dateString, int days) throws ParseException { DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); Date inputDate = dateFormat.parse(dateString); Calendar cal = Calendar.getInstance(); cal.setTime(inputDate); int dayOfYear = cal.get(Calendar.DAY_OF_YEAR); cal.set(Calendar.DAY_OF_YEAR, dayOfYear - days); return cal.getTime(); } /** * 获取某月上一个月份 * @return Date */ public Date getMonthsBefore(String dateString, int months) throws ParseException { DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); Date inputDate = dateFormat.parse(dateString); Calendar cal = Calendar.getInstance(); cal.setTime(inputDate); int monthOfYear = cal.get(Calendar.MONTH); cal.set(Calendar.MONTH, monthOfYear - months); return cal.getTime(); } /** * 获取某月第一天日期 * @return Date */ public Date getFisrtDayOfMonth(String dateString) throws ParseException { DateFormat dateFormat = new SimpleDateFormat("yyyyMM"); Date inputDate = dateFormat.parse(dateString); Calendar cal = Calendar.getInstance(); cal.setTime(inputDate); int firstDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH); cal.set(Calendar.DAY_OF_MONTH, firstDay); return cal.getTime(); } /** * 获取某月最后一天日期 * @return Date */ public Date getLastDayOfMonth(String dateString) throws ParseException { DateFormat dateFormat = new SimpleDateFormat("yyyyMM"); Date inputDate = dateFormat.parse(dateString); Calendar cal = Calendar.getInstance(); cal.setTime(inputDate); int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH); cal.set(Calendar.DAY_OF_MONTH, lastDay); return cal.getTime(); } /** * 获取最后一个月的第一天日期 * @return Date */ public static String getLastMonthFirstDay() { Calendar cal_1 = Calendar.getInstance(); cal_1.add(Calendar.MONTH, -1); cal_1.set(Calendar.DAY_OF_MONTH, 1); String firstDay = format.format(cal_1.getTime()); System.out.println("-----1------firstDay:" + firstDay); return firstDay; } /** * 获取最后一个月最后一天日期 * @return Date */ public static String getLastMonthlastDay() { Calendar cale = Calendar.getInstance(); cale.set(Calendar.DAY_OF_MONTH, 0); String lastDay = format.format(cale.getTime()); System.out.println("-----2------lastDay:" + lastDay); return lastDay; } /** * 获取当前月第一天日期 * @return Date */ public static String getCurrentMonthFirstDay() { 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:" + first); return first; } /** * 获取当前月最后一天日期 * @return Date */ public static String getCurrentMonthlastDay() { 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:" + last); return last; } /** * 获取当前年份第一天日期 * @return Date */ public static Date getCurrYearFirst() { Calendar currCal = Calendar.getInstance(); int currentYear = currCal.get(Calendar.YEAR); return getYearFirst(currentYear); } /** * 根据传入的参数获取该年的第一天 * @return Date */ public static Date getCurrYearFirst(String dateString) throws ParseException { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date inputDate = dateFormat.parse(dateString); Calendar cal = Calendar.getInstance(); cal.setTime(inputDate); int currentYear = cal.get(Calendar.YEAR); return getYearFirst(currentYear); } /** * 根据传入的参数获取该年月 * @return Date */ public static String getMonth(String dateString) throws ParseException { DateFormat dateFormat = new SimpleDateFormat("MM"); Date inputDate = dateFormat.parse(dateString); Calendar cal = Calendar.getInstance(); cal.setTime(inputDate); return formatDate(cal.getTime()); } /** * 获取当前年份最后一天 * @return Date */ public static Date getCurrYearLast() { Calendar currCal = Calendar.getInstance(); int currentYear = currCal.get(Calendar.YEAR); return getYearLast(currentYear); } /** * 根据传入的参数获取该年 * @return Date */ public static Date getYearFirst(int year) { Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(Calendar.YEAR, year); Date currYearFirst = calendar.getTime(); return currYearFirst; } /** * 根据传入的参数获取该年 * @return Date */ public static Date getYearLast(int year) { Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(Calendar.YEAR, year); calendar.roll(Calendar.DAY_OF_YEAR, -1); Date currYearLast = calendar.getTime(); return currYearLast; } /** * 根据传入的参数获取该年月 * @return Date */ public static String getCurrentYear(){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy"); Date date = new Date(); return sdf.format(date);} /** * 根据传入的参数获取该年月 * @return Date */ public static String getLastYear() { Calendar date = Calendar.getInstance(); date.add(Calendar.YEAR, -1); String year = String.valueOf(date.get(Calendar.YEAR)); return year; } /** * 现在时间+6个月与next_time比较 * @return */ public static String getStaleDated(){ SimpleDateFormat sdfTimeStamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.sss"); Date date= new Date(); Calendar cd = Calendar.getInstance(); cd.setTime(date); cd.add(Calendar.MONTH, 6); date=cd.getTime(); String stale_dated = sdfTimeStamp.format(date); return stale_dated; } /** * 获取当前时间 * @return */ public static String currentDatetime(){ SimpleDateFormat tempDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String datetime = tempDate.format(new java.util.Date()); return datetime; } /** * 获取当前时间 * * @return */ public static String getYyMmtime() { SimpleDateFormat tempDate = new SimpleDateFormat("yyyy-MM"); String datetime = tempDate.format(new java.util.Date()); return datetime; } /** * 日期计算 * @param date * @param type * @param number * @return */ public static String calculateDate(String date,String type,int number){ try{ // SimpleDateFormat sdfTimeStamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.sss"); SimpleDateFormat sdfTimeStamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //String create_time = sdfTimeStamp.format(new Date()); Date tmpDate = sdfTimeStamp.parse(date); Calendar cd = Calendar.getInstance(); cd.setTime(tmpDate); if(type.equals("m")){ cd.add(Calendar.MONTH, number); }else if (type.equals("d")){ cd.add(Calendar.DAY_OF_MONTH, number); }else { return "type is unknown"; } tmpDate = cd.getTime(); String dateRuslt = sdfTimeStamp.format(tmpDate); return dateRuslt; }catch(Exception ex){ return "calculate failed"; } } public static Date getDateByStr(String string){ //String string = "2016-10-24 21:59:06"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date =null; try{ date = sdf.parse(string); System.out.println(sdf.parse(string)); }catch (Exception e){ e.printStackTrace(); } return date; } public static String getStrByDate(Date date) { //String string = "2016-10-24 21:59:06"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateTime = null; try { dateTime = sdf.format(date); } catch (Exception e) { e.printStackTrace(); } return dateTime; } public static String getUpdateTime(){ //当前时间重写更新时间 SimpleDateFormat sdfTimeStamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.sss"); String update_time = sdfTimeStamp.format(new Date()); return update_time; } public static void main(String[] args) throws ParseException { DateUtil dateTest = new DateUtil(); // DateFormat df = new SimpleDateFormat("yyyyMMdd"); // Date before7Day = dateTest.getDaysBefore("20140301", 7); // System.out.println(df.format(before7Day)); // Date testFirstDay = dateTest.getLastDayOfMonth("201407"); // System.out.println(df.format(testFirstDay)); // Date testBeforeMonth = dateTest.getMonthsBefore("20140712", 12); // System.out.println(df.format(testBeforeMonth)); // DateFormat df2 = new SimpleDateFormat("yyyyMM"); // Date getFisrtDayOfMonth = dateTest.getFisrtDayOfMonth("201407"); // System.out.println(df2.format(getFisrtDayOfMonth)); System.out.println(getStaleDated()); // System.out.println(formatDate(getCurrYearLast()));// String stObj="2016-3-21";// String[] timeDay = stObj.split("-");// System.out.println(timeDay[1]); } }

优秀的个人博客,低调大师

Java 常用类库 之 Timer TimerTask

http://www.verejava.com/?id=17159702655333 import java.text.SimpleDateFormat; import java.util.Date; import java.util.Timer; import java.util.TimerTask; public class Test1 { private Timer timer; public Test1() { timer = new Timer(); //每隔 1 秒 显示当前时间 timer.schedule(new MyTask(), new Date(), 1000); } class MyTask extends TimerTask { @Override public void run() { //打印当前时间 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println(df.format(new Date())); } } public static void main(String[] args) { new Test1(); } } http://www.verejava.com/?id=17159702655333

优秀的个人博客,低调大师

微信‘类’之测试方法汇总

前言 小程序优势之一,是可以同时在不同设备上运行,但这会带来潜在兼容性问题。这个问题对于个人开发者而言很麻烦,因为他们通常只会用自己的手机来测试小程序。当然,微信早就意识到这个问题,并在早先的新能力更新中,为小程序开发者提供了免费的真机测试工具。 微信提供的这个工具,不需要自己准备测试手机。这个工具已经免费为你提供了大量 Android 机型供你测试,你需要做的,就是点点鼠标、申请测试。 在最新版、测试版「微信 Web 开发者工具」中,都内置了这个工具。在开发者工具中,点击右上角的「测试」按钮,就可以查看以往申请过的测试报告。 一、真机工具下载地址 1、beta 版本微信 Web 开发者工具 2、最新版微信 Web 开发者工具正式版 二、Airtest AirtestIDE是一个跨平台的UI自动化测试编辑器,适用于游戏和App。 1、自动化脚本录制、一键回放、报告查看,轻而易举实现自动化测试流程 2、支持基于图像识别的Airtest框架,适用于所有Android和Windows游戏 3、支持基于UI控件搜索的Poco框架,适用于Unity3d,Cocos2d与Android App 4、访问官网通过视频查看更多特性 5、具体实现步骤参考【suyuchen123】同学写的使用Airtest进行Android与iOS的微信小程序自动化测试 三、Appium+Chrome 1、使用Appium框架+Chrome调试工具 四、微信小程序实现自动化 1、参考案例:微信小程序实现自动化 五、一行代码让微信小程序支持 cookie 1.参考案例:一行代码让微信小程序支持cookie 六、微信小程序远程调试 1.参考案例:微信小程序远程调试

优秀的个人博客,低调大师

Java并发-线程安全的集合类

注意,此处所提供的代码,都是基于JDK1.8版本,部分代码与之前版本存在较大差异 1、Hashtable:通过synchronized关键字保证线程安全 2、ConcurrentHashMap:效率比Hashtable高,主要体现在前者使用了锁分离技术,即代码块锁,而不是方法锁 保证线程安全的方法(JDK1.8中):在ConcurrentHashMap中,随处可以看到U, 大量使用了U.compareAndSwapXXX的方法,这个方法是利用一个CAS算法实现无锁化的修改值的操作,他可以大大降低锁代理的性能消耗。这个算法的基本思想就是不断地去比较当前内存中的变量值与你指定的一个变量值是否相等,如果相等,则接受你指定的修改的值,否则拒绝你的操作。因为当前线程中的值已经不是最新的值,你的修改很可能会覆盖掉其他线程修改的结果。这一点与乐观锁,SVN的思想是比较类似的。 3、CopyOnWriteArrayList:实现原理比较简单,就是利用之前写过的Java中的锁ReentrantLock进行加锁处理,写操作进行加锁处理,读操作则是利用复制容器的方式 4、CopyOnWriteArraySet:CopyOnWriteArrayList的装饰器模式 CopyOnWrite容器,即写时复制的容器,通俗理解就是当我们往一个容器中添加元素的时候,不直接往当前容器中添加,而是先将当前容器进行copy,复制出一个新的容器,然后新的容器里面添加元素,添加完元素之后,再将原容器的引用指向新的容器,这样做的好处是我们可以对CopyOnWrite容器进行并发的读,而不需要加锁,因为当前容器不会添加任何元素,但是添加元素的时候需要加锁,防止多个并发线程搞出多个复制容器来 所以CopyOnWrite容器比较多用于读多写少的并发场景,比如白名单,黑名单,商品类目的访问和更新等场景, CopyOnWrite的注意: 1、减少扩容开销 2、尽可能使用批量添加 CopyOnWrite的缺点: 1、内存占用,复制容器的时候同时存在两个容器,而且写完之后,由于垃圾处理机制的原因,原容器可能还会留存一段时间 2、数据一致性问题,只能保证数据的最终一致性,不能保证数据的实时一致性 5、Vector 矢量队列,实现了List,通过synchronized关键字保证线程安全,跟Hashtable类似 6、StringBuffer和StringBuilder中,Stringbuffer是线程安全的,通过synchronized关键字保证线程安全。 最后复制粘贴一些关于CAS的文章链接,感觉说的挺好的 https://blog.csdn.net/hsuxu/article/details/9467651

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码