日期工具类DateUtil

Android开发中日期工具类DateUtil完整实例 主要介绍了Android开发中日期工具类DateUtil,结合完整实例形式分析了Android针对日期与时间的计算、转换、格式化、获取等相关操作技巧,需要的朋友可以参考下 立即下载
package com.yxb.base.util;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.time.DateUtils;

public class DateUtil extends DateUtils {
    public static String[] parsePatterns = new String[]{"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm"};

    public DateUtil() {
    }

    public static String getDate() {
        return getDate("yyyy-MM-dd");
    }

    public static String getDate(String pattern) {
        return DateFormatUtils.format(new Date(), pattern);
    }

    public static String formatDate(Date date, Object... pattern) {
        String formatDate = null;
        if (pattern != null && pattern.length > 0) {
            formatDate = DateFormatUtils.format(date, pattern[0].toString());
        } else {
            formatDate = DateFormatUtils.format(date, "yyyy-MM-dd HH:mm:ss");
        }

        return formatDate;
    }

    public static String formatDateString(String date, Object... pattern) {
        String formatDate = null;

        try {
            if (pattern != null && pattern.length > 0) {
                formatDate = DateFormatUtils.format(formatDate(date, "yyyy-MM-dd HH:mm:ss"), pattern[0].toString());
            } else {
                formatDate = DateFormatUtils.format(formatDate(date, "yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd");
            }

            return formatDate;
        } catch (Exception var4) {
            return formatDate;
        }
    }

    public static Date formatDate(String date, String format) {
        try {
            if (StringUtil.isEmpty(format)) {
                format = "yyyy-MM-dd HH:mm:ss";
            }

            return (new SimpleDateFormat(format)).parse(date);
        } catch (Exception var3) {
            var3.printStackTrace();
            return new Date();
        }
    }

    public static String formatDateTime3(long timestemp) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(new Date(timestemp));
    }

    public static String getTime() {
        return formatDate(new Date(), "HH:mm:ss");
    }

    public static String getDateTime() {
        return formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
    }

    public static String getDateTime2() {
        return formatDate(new Date(), "yyyyMMddHHmmss");
    }

    public static String getYear() {
        return formatDate(new Date(), "yyyy");
    }

    public static String getMonth() {
        return formatDate(new Date(), "MM");
    }

    public static String getMonth(Date date) {
        return formatDate(date, "MM");
    }

    public static String getMonth(String datestr) {
        return formatDate(parseDate(datestr), "MM");
    }

    public static String getDay() {
        return formatDate(new Date(), "dd");
    }

    public static String getStringWeek() {
        return formatDate(new Date(), "E");
    }

    public static int getIntWeek(Date date) {
        Calendar cal = Calendar.getInstance();
        if (date == null) {
            cal.setTime(new Date(System.currentTimeMillis()));
        } else {
            cal.setTime(date);
        }

        int tempWeek = cal.get(7);
        return tempWeek == 1 ? 7 : tempWeek - 1;
    }

    public static Date parseDate(Object str) {
        if (str == null) {
            return null;
        } else {
            try {
                return parseDate(str.toString(), parsePatterns);
            } catch (ParseException var2) {
                return null;
            }
        }
    }

    public static long pastDays(Date date) {
        long t = (new Date()).getTime() - date.getTime();
        return t / 86400000L;
    }

    public static String[] getMonthDayArray(String datestr) {
        SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM");
        Calendar rightNow = Calendar.getInstance();

        try {
            rightNow.setTime(simpleDate.parse(datestr.substring(0, 4) + "-" + datestr.substring(4, 6)));
        } catch (ParseException var6) {
            var6.printStackTrace();
        }

        int day = rightNow.getActualMaximum(5);
        String[] days = new String[day];

        for(int i = 0; i < day; ++i) {
            if (i < 10) {
                if (i == 9) {
                    days[i] = datestr.substring(4, 6) + "-" + (i + 1);
                } else {
                    days[i] = datestr.substring(4, 6) + "-0" + (i + 1);
                }
            } else {
                days[i] = datestr.substring(4, 6) + "-" + (i + 1);
            }
        }

        return days;
    }

    public static int getMonthDays(String datestr) {
        SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM");
        Calendar rightNow = Calendar.getInstance();

        try {
            rightNow.setTime(simpleDate.parse(datestr));
        } catch (ParseException var4) {
            var4.printStackTrace();
        }

        return rightNow.getActualMaximum(5);
    }

    public static Date getDateStart(Date date) {
        Date datetemp = date;
        if (date == null) {
            return null;
        } else {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            try {
                datetemp = sdf.parse(formatDate(date, "yyyy-MM-dd") + " 00:00:00");
            } catch (ParseException var4) {
                var4.printStackTrace();
            }

            return datetemp;
        }
    }

    public static Date getDateEnd(Date date) {
        Date datetemp = date;
        if (date == null) {
            return null;
        } else {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            try {
                datetemp = sdf.parse(formatDate(date, "yyyy-MM-dd") + " 23:59:59");
            } catch (ParseException var4) {
                var4.printStackTrace();
            }

            return datetemp;
        }
    }

    public static Long getStringTimeDifference(String before, String after) {
        return getTimeDifference(parseDate(before), parseDate(after));
    }

    public static Long getTimeDifference(Date before, Date after) {
        return (after.getTime() - before.getTime()) / 1000L;
    }

    public static int daysBetween(Date start, Date end) {
        Calendar calst = Calendar.getInstance();
        Calendar caled = Calendar.getInstance();
        calst.setTime(start);
        caled.setTime(end);
        calst.set(11, 0);
        calst.set(12, 0);
        calst.set(13, 0);
        caled.set(11, 0);
        caled.set(12, 0);
        caled.set(13, 0);
        return ((int)(caled.getTime().getTime() / 1000L) - (int)(calst.getTime().getTime() / 1000L)) / 3600 / 24;
    }

    public static int daysBetween(String before, String after) {
        Date beforeDate = new Date();
        Date afterDate = new Date();
        DateFormat df = DateFormat.getDateInstance();

        try {
            beforeDate = df.parse(before);
            afterDate = df.parse(after);
        } catch (ParseException var7) {
            var7.printStackTrace();
        }

        Calendar calst = Calendar.getInstance();
        Calendar caled = Calendar.getInstance();
        calst.setTime(beforeDate);
        caled.setTime(afterDate);
        calst.set(11, 0);
        calst.set(12, 0);
        calst.set(13, 0);
        caled.set(11, 0);
        caled.set(12, 0);
        caled.set(13, 0);
        return ((int)(caled.getTime().getTime() / 1000L) - (int)(calst.getTime().getTime() / 1000L)) / 3600 / 24;
    }

    public static int dayBetween(String smdate, String bdate) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        cal.setTime(sdf.parse(smdate));
        long time1 = cal.getTimeInMillis();
        cal.setTime(sdf.parse(bdate));
        long time2 = cal.getTimeInMillis();
        long between_days = (time2 - time1) / 86400000L;
        return Integer.parseInt(String.valueOf(between_days));
    }

    public static long getTodaySurplusTime() {
        Date nowDate = new Date();
        return (getDateEnd(nowDate).getTime() - nowDate.getTime()) / 1000L;
    }

    public static long dateDiff(String startTime, String endTime, String format, String str) {
        SimpleDateFormat sd = new SimpleDateFormat(format);
        long nd = 86400000L;
        long nh = 3600000L;
        long nm = 60000L;
        long ns = 1000L;
        long day = 0L;
        long hour = 0L;
        long min = 0L;
        long sec = 0L;

        try {
            long diff = sd.parse(endTime).getTime() - sd.parse(startTime).getTime();
            day = diff / nd;
            hour = diff % nd / nh + day * 24L;
            min = diff % nd % nh / nm + day * 24L * 60L;
            sec = diff % nd % nh % nm / ns;
            return str.equalsIgnoreCase("h") ? hour : min;
        } catch (ParseException var24) {
            var24.printStackTrace();
            return str.equalsIgnoreCase("h") ? hour : min;
        }
    }

    public static String getFormatDateString(String datestr) {
        return datestr.substring(0, 4) + "-" + datestr.substring(4, 6) + "-" + datestr.substring(6, 8) + " " + datestr.substring(8, 10) + ":" + datestr.substring(10, 12) + ":" + datestr.substring(12, 14);
    }

    public static boolean compare(Date oldDate, Date newDate) {
        return oldDate.getTime() > newDate.getTime();
    }

    public static boolean isSameDay(String sDate1, String sDate2) {
        sDate1 = sDate1.substring(0, 10);
        sDate2 = sDate2.substring(0, 10);
        return sDate1.equals(sDate2);
    }

    public static String getStringBeforeDay(Integer day) {
        return formatDate(getBeforeDay(new Date(), day), "yyyy-MM-dd");
    }

    public static String getStringBeforeDay(Date currentDate, Integer day) {
        return formatDate(getBeforeDay(currentDate, day), "yyyy-MM-dd");
    }

    public static Date getBeforeDay(Date currentDate, Integer day) {
        return day == null ? null : getBeforeDateTime(currentDate, day * 24 * 60);
    }

    public static String getStringBeforeDateTime(Date currentDate, Integer min) {
        return formatDate(getBeforeDateTime(currentDate, min), "yyyy-MM-dd HH:mm:ss");
    }

    public static Date getBeforeDateTime(Date currentDate, Integer min) {
        if (currentDate != null && min != null) {
            Long current = currentDate.getTime();
            return new Date(current - Long.parseLong(min + "") * 60L * 1000L);
        } else {
            return null;
        }
    }

    public static long getLastTime() {
        long milliSecondsLeftToday = 86400000L - DateUtils.getFragmentInMilliseconds(Calendar.getInstance(), 5);
        return milliSecondsLeftToday == 0L ? 0L : milliSecondsLeftToday / 1000L;
    }

    public static String getFrontMonth(int month) {
        Calendar cal = Calendar.getInstance();
        cal.add(2, -month);
        return formatDate(cal.getTime(), "yyyy-MM");
    }

    public static String getBeforeHour(int hour) {
        Calendar cal = Calendar.getInstance();
        cal.add(10, -hour);
        return formatDate(cal.getTime(), "yyyy-MM-dd HH:mm:ss");
    }

    public static String getBeforeHour(Date nowDate, int hour) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(nowDate);
        cal.add(10, -hour);
        return formatDate(cal.getTime(), "yyyy-MM-dd HH:mm:ss");
    }

    public static String[] getStartToEndHour(String startTime, String endTime) {
        Date startDate = parseDate(startTime);
        Date endDate = parseDate(endTime);
        return getStartToEndHour(startDate, endDate);
    }

    public static String[] getStartToEndHour(Date startTime, Date endTime) {
        long time = endTime.getTime() - startTime.getTime();
        int hour = (int)(time / 1000L / 60L / 60L);
        String[] hours = new String[hour];

        for(int i = 0; i < hour; ++i) {
            hours[i] = getBeforeHour(startTime, -i);
        }

        return hours;
    }

    public static String[] getBeforeDayToNowDay(int day) {
        String[] days = new String[day + 1];

        for(int i = day; i >= 0; --i) {
            days[day - i] = getStringBeforeDay(i);
        }

        return days;
    }

    public static String[] getStartToNowDay(String startTime) {
        Date startDate = parseDate(startTime);
        long time = (new Date()).getTime() - startDate.getTime();
        int day = (int)(time / 1000L / 60L / 60L / 24L);
        String[] days = new String[day];

        for(int i = 0; i < day; ++i) {
            days[i] = getStringBeforeDay(startDate, -i);
        }

        return days;
    }

    public static String[] getNowBeforeMonth(int month) {
        String[] months = new String[month + 1];
        Calendar cal = null;

        for(int i = 0; i <= month; ++i) {
            cal = Calendar.getInstance();
            cal.add(2, -(month - i));
            months[i] = formatDate(cal.getTime(), "yyyy-MM");
        }

        return months;
    }

    public static String[] getBeforeMonthToAMounthBefore(int month) {
        String[] months = new String[month];
        Calendar cal = null;

        for(int i = 0; i < month; ++i) {
            cal = Calendar.getInstance();
            cal.add(2, -(month - i));
            months[i] = formatDate(cal.getTime(), "yyyy-MM");
        }

        return months;
    }

    public static String getBeforeMonth(int month) {
        Calendar cal = Calendar.getInstance();
        cal.add(2, -month);
        return formatDate(cal.getTime(), "yyyy-MM");
    }

    public static String getLastDayOfMonth(String month) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
        Date date = null;

        try {
            date = dateFormat.parse(month);
        } catch (Exception var5) {
        }

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(2, 1);
        calendar.add(5, -1);
        Date voucherDate = calendar.getTime();
        return formatDate(voucherDate, "yyyy-MM-dd");
    }
}

YOLOv5实战:无人机巡检图片差异对比与违建标记(附完整代码) 本文详细介绍了如何利用YOLOv5目标检测技术实现无人机巡检图片差异对比与违建标记。通过图像对齐、目标检测、差异分析和可视化标记四个步骤,构建高效的违建识别系统,显著提升城市管理效率。文章包含完整代码实现和性能优化技巧,为计算机视觉在无人机巡检中的应用提供实用指南。 阅读详情

相关推荐

基于STM32+OV7670的图像采集系统(基础篇:ov7670介绍)

一、简单认识 先来看一下外观: OV7670,图像传感器,体积小,工作电压低,提供单片VGA摄像头和影像处理器的所有功能。通过SCCB总线控制,可以输入整帧、子采样、取窗口等方式的各种分辨率8位影像数据。 其他介绍比较繁琐,这里就不一一赘述了,我们只需要知道它是通过SCCB总线控制的就行了。 带FIFO与不带FIFO 目前市场上购买的ov7670模块分为两种,一种是不带FIFO芯片、一种是带FIFO芯片的。 FIFO是什么:(First Input First Output)先入先出的意思,

m0_59113542的博客 4万+

DateUtil工具类

基于LocalDateTime的日期工具类

zhourongxiang1的博客 209

发票OFD格式转换成PDF

发票OFD格式转换成PDF

Be_insighted的博客 934

【Android】DateUtil(时间工具类)

DateUtil,时间工具类 Crazy Coding /** * @author Mozhimen / Kolin Zhao * @date 2020/4/5 */ public class DateUtil { public final static String format_yyyyMMddhhmmss = "yyyy-MM-dd HH:mm:ss"; public final static String format_yyyyMMddhhmm = "yyyy-MM-d

weixin_42473228的博客 2596

03.Linux下目录动态扩容,以分配home的部分空间给root为例

本篇文章将介绍Linux下分配home目录的部分空间给root目录。大致思路:卸载home,解除其磁盘容量占用->扩容root,增加其磁盘空间->重建恢复home操作演示环境为CentOS系统,其他操作系统例如openEuler也可作为参考。01.Linux下目录扩容,以增加root目录的磁盘容量分配为例操作系统版本如下名称版本CentOS7.6+

ChennyWJS的博客 2337

PCIE2.0/PCIE3.0/PCIE4.0/PCIE5.0接口的带宽、速率计算

一、PCIE接口速率: 二、PCIE相关概念: 传输速率为每秒传输量GT/s,而不是每秒位数Gbps,因为传输量包括不提供额外吞吐量的开销位; 比如 PCIe 1.x和PCIe 2.x使用8b / 10b编码方案,导致占用了20% (= 2/10)的原始信道带宽。 GT/s —— Giga transation per second (千兆传输/秒),即每一秒内传输的次数。重点在于描述物理层通信协议的速率属性,可以不和链路宽度等关联。 Gbps —— Giga Bits Per Second

技术联盟 1万+

DateUtil 工具类

【代码】DateUtil 工具类。

qq_30272167的博客 441

地下管网巡检机器人:基于YOLOv8与UI界面的智能化系统设计与实现

通过YOLOv8模型的目标检测功能结合实时视频流,我们能够实现对地下管网巡检机器人的智能化控制。系统通过图像识别技术帮助巡检人员快速识别管道中的各种缺陷和障碍物,从而提高巡检效率和准确性。未来,我们可以继续优化模型,增加更多的目标类别,并通过强化学习等方法提高机器人的自主巡检能力。此外,随着硬件技术的发展,未来的巡检机器人可能会具备更强的感知能力和更高的智能水平。

YOLO 533

Date工具类

package com.yunmunan.browser.demo; /** @Author: CloudyChen @Date: 2019/5/18 13:32 @Description: ${description} @Version: 1.0 */ import java.sql.Timestamp; import java.text.ParseException; import java...

weixin_45320866的博客 341

零基础 ABAP 学习教程系列文章的目录

曾几何时,ABAP 就是 SAP 的代名词。ABAP 这门编程语言造就了 SAP 名噪一时的 R/3 产品,同时也是如今 SAP 旗舰级产品,SAP S/4HANA 底层的实现语言。 ABAP 不仅代表着 SAP 这家公司在企业级管理软件市场辉煌的过去,ABAP 自身也在不断地进化着。SAP 不仅在本地部署(On-Premise)领域继续保持着自己绝对的统治地位,而且在云应用领域(Software-as-a-Service, 简称 SaaS), 也推出了自己的解决方案,比如 SAP S/4HANA Clo

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 2万+

Spring AI 项目实战(十八):Spring Boot + AI + Vue3 + OSS + DashScope 实现高效语音识别系统(附完整源码)

本文介绍基于 Spring Boot AI 集成阿里云 OSS 与 DashScope 语音识别 API 的高效语音识别系统。该系统通过云端存储音频文件,解决传统本地存储的性能瓶颈与存储压力,支持同步 / 异步语音转文本,实现文件自动生命周期管理。文中详述技术选型、架构设计、核心代码实现(含前后端及配置)、部署流程,展现其高并发处理、可靠文件管理能力,适用于客服、教育等企业级场景,为语音识别应用提供实用解决方案。

博客 1537

【Java】Java中的日期转化格式DateUtil工具类-(87个方法)

【代码】Java中的日期转化格式DateUtil工具类-(87个方法)

tttzzzqqq2018的博客 4503

【模型实战】MiMo-VL-7B讲解与实战

维度成绩MMMU70.6(图像理解最难测试之一)VideoMME70.8(视频理解标杆)59.4(超越78B参数模型)56.1(超过专用GUI模型)Elo评分开源VLM排名第一(7B~72B)社区热度过去一个月下载超1,600次(RL+SFT)📌一句话概括MiMo-VL 是目前性能最强、推理最稳、体验最佳、生态最全的7B级开源视觉语言模型。

m0_47867638的博客 1200

java日期工具类DateUtil

一名优秀的程序员,不仅需要有着丰富解决问题的方案,还需要的便是代码的沉淀,这不仅有助于自己快速的开发程序,也有利于保证程序的健壮。那如何才能沉淀自己的”代码“呢?从自己编写util开始其实就是一个不错的选择。 虽然网络上也有类似的工具类,但我愿意自己写的原因有三: 1、好代码并不容易找,不满足需要的倒是不少 2、可能存在未知的bug 3、丧失了巩固和提高自己的机会 废话不多说,我的源码如

鹏霄万里展雄飞 3万+

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

鸿蒙NEXT开发日期工具类DateUtil(ArkTs)

鸿蒙NEXT开发日期工具类(ArkTs)

鸿蒙布道师 2269

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

harmony-utils之DateUtil,日期工具类

摘要: harmony-utils是鸿蒙系统的一款多功能工具库,其中DateUtil提供了丰富的日期处理方法,包括日期格式化、日期比较、日期计算等功能。支持时间戳、字符串、Date对象等多种日期类型输入,可实现获取当前日期、判断闰年、计算日期差、获取前后日期等常见操作。如getFormatDate进行日期格式化,compareDays计算日期差值,getBeforeDay获取前一天日期等。该工具类简化了鸿蒙应用开发中的日期处理,支持20多种日期格式,满足各类业务场景需求。需在UIAbility中初始化后使用

qq_32922545的博客 845

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

Java日期工具类DateUtil详解:简化日期操作的利器

**文章摘要:** 本文介绍了一个功能强大的Java日期工具类`DateUtil`,它封装了常见的日期操作,包括日期格式化、解析、加减、比较等。通过使用`DateUtil`,开发者可以轻松处理各种日期相关的需求,避免重复编写日期处理代码,提高开发效率。文章详细讲解了`DateUtil`的核心方法,如日期格式化、解析、加减操作、日期比较等,并提供了丰富的代码示例。此外,`DateUtil`还提供了获取特定日期(如昨天、明天、上个月、下周等)以及当前周起始和结束日期的功能。通过引入`DateUtil`,开发者

qq_42763903的博客 1610

dateutil 日期计算_使用日期工具类:DateUtil

importjava.text.DateFormat;importjava.text.ParseException;importjava.text.SimpleDateFormat;importjava.util.Calendar;importjava.util.Date;importjava.util.GregorianCalendar;importjava.util.Locale;import...

weixin_39691233的博客 677

java日期工具类DateUtil-续二

该版本是一次较大的升级,农历相比公历复杂太多(真佩服古人的智慧),虽然有规律,但涉及到的取舍、近似的感念太多,况且本身的概念就已经很多了,我在网上也是查阅了很多的资料,虽然找到一些计算的方法,但都有些计算缺陷,后来才终于找到“寿天星文历”:一个十分精准的万年历。虽然它的功能十分强大,但相对的涉及到的计算也很多,逻辑和思路都相当的复杂了,维护成本很大,有时候项目中并不一定要用到这么强大的农历,因此该

鹏霄万里展雄飞 9056

DateUtil 日期工具类

本文介绍了DateUtil日期工具类的设计与实现。该工具类采用线程安全的SimpleDateFormat缓存机制,提供日期格式化(format)、字符串解析(parse)等基础功能,并扩展实现了获取N天前日期(getBeforeDayDate/getDayAgo)和生成过去N天日期列表(getBeforeDates)等实用方法。通过封装Calendar和LocalDate操作,简化了常见日期处理需求,支持多种日期模式,兼顾线程安全与性能。

qq_45751976的博客 43

java日期工具类DateUtil-续一

上篇文章中,我为大家分享了下DateUtil第一版源码,但就如同文章中所说,我发现了还存在不完善的地方,所以我又做了优化和扩展。更新日志:1、修正当字符串日期风格为MM-dd或yyyy-MM时,若日期太大或太小后,识别日期错误。2、修正识别日期算法(getAccurateDate)bug。3、修正计算日期天数差(getIntervalDays)bug。2、优化DateUtil处理日期的速度。2、优...

weixin_30649641的博客 94

MathUtil(数学工具类) 、DateUtil(日期工具类)

Util工具类代码

拾光、的样子 292

dateutil 日期计算_计算日期工具类

package com.niu.afsale.common.utils;import com.niu.afsale.common.AfsaleConstants;import org.slf4j.Logger;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Calendar;import j...

weixin_39990401的博客 201
上一篇: HttpURLConnection与HttpClient浅析
下一篇: 返回结果实体类ResultData
hit、run
博客等级 码龄10年 163粉丝 157原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值