Java8操作日期

Date类转Java8新时间类看这一篇就够了,Date转LocalDate,LocalTime,LocalDateTime,ZonedDateTime,OffsetDateTime方法大全! 阅读详情

一、Date与LocalDate互转

  • Date转LocalDate
 public static void main(String[] args) {
        Date date = new Date();
        LocalDate localDate = LocalDate.now();
        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println("date2LocalDate:"+date2LocalDate(date));
    }
 
    /**
     * Date转LocalDate
     * @param date
     */
    public static LocalDate date2LocalDate(Date date) {
        if(null == date) {
            return null;
        }
        return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
    }
  • LocalDate转Date
public static void main(String[] args) {
        Date date = new Date();
        LocalDate localDate = LocalDate.now();
        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println("localDate2Date:"+localDate2Date(localDate));
    }
    /**
     * LocalDate转Date
     * @param localDate
     * @return
     */
    public static Date localDate2Date(LocalDate localDate) {
        if(null == localDate) {
            return null;
        }
        ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault());
        return Date.from(zonedDateTime.toInstant());
    }
  • String转LocalDateTime
 DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            LocalDateTime startTime = LocalDateTime.parse(params.getLeaseEndTime()+" 00:00:00",df);
            LocalDateTime endTime = LocalDateTime.parse(params.getLeaseEndTime()+" 23:59:59",df);
            ZoneId zoneId = ZoneId.systemDefault();
            criteria.andModifyTimeBetween(Date.from(startTime.atZone(zoneId).toInstant()),Date.from(endTime.atZone(zoneId).toInstant()));

二、日期初识

  示例1: 获取当天日期

    Java 8中的 LocalDate 用于表示当天日期。和java.util.Date不同,它只有日期,不包含时间。

public static void main(String[] args) {
  LocalDate date = LocalDate.now();
  System.out.println("当前日期=" + date);
}

  示例2: 构造指定日期

    调用工厂方法LocalDate.of()创建任意日期, 该方法需要传入年、月、日做参数,返回对应的LocalDate实例。这个方法的好处是没再犯老API的设计错误,比如年度起始于1900,月份是从0开 始等等

public static void main(String[] args) {
    LocalDate date = LocalDate.of(2000, 1, 1);
    System.out.println("千禧年=" + date);
}

  示例3: 获取年月日信息

public static void main(String[] args) {
    LocalDate date = LocalDate.now();
    System.out.printf("年=%d, 月=%d, 日=%d", date.getYear(), date.getMonthValue(), date.getDayOfMonth());
}

  示例4: 比较两个日期是否相等

public static void main(String[] args) {
    LocalDate now = LocalDate.now();
    LocalDate date = LocalDate.of(2018, 9, 24);
    System.out.println("日期是否相等=" + now.equals(date));
}

    示例5:计算日期相差多少

LocalDate localDate1 = LocalDate.of(2017, 9, 1);
LocalDate localDate2 = LocalDate.of(2017, 10, 2);
Period next = Period.between(localDate1, localDate2);
System.out.println((int) (localDate2.toEpochDay() - localDate1.toEpochDay()));

三、时间初识

  示例: 获取当前时间

    Java 8中的 LocalTime 用于表示当天时间。和java.util.Date不同,它只有时间,不包含日期。

public static void main(String[] args) {
    LocalTime time = LocalTime.now();
    System.out.println("当前时间=" + time);
}

    计算时间相差多少

LocalDateTime now = LocalDateTime.now();
System.out.println("计算两个时间的差:");
LocalDateTime end = LocalDateTime.now();
Duration duration = Duration.between(now,end);
long days = duration.toDays(); //相差的天数
long hours = duration.toHours();//相差的小时数
long minutes = duration.toMinutes();//相差的分钟数
long millis = duration.toMillis();//相差毫秒数
long nanos = duration.toNanos();//相差的纳秒数
System.out.println(now);
System.out.println(end);

四、比较与计算

  示例1: 日期时间计算

    Java8提供了新的plusXxx()方法用于计算日期时间增量值,替代了原来的add()方法。新的API将返回一个全新的日期时间示例,需要使用新的对象进行接收。

 public static void main(String[] args) {
        
     // 时间增量
        LocalTime time = LocalTime.now();
        LocalTime newTime = time.plusHours(2);
        System.out.println("newTime=" + newTime);
        
     // 日期增量
        LocalDate date = LocalDate.now();
        LocalDate newDate = date.plus(1, ChronoUnit.WEEKS);
        System.out.println("newDate=" + newDate);
        
    }

  示例2: 日期时间比较

    Java8提供了isAfter()、isBefore()用于判断当前日期时间和指定日期时间的比较

 public static void main(String[] args) {
        
        LocalDate now = LocalDate.now();
        
        LocalDate date1 = LocalDate.of(2000, 1, 1);
        if (now.isAfter(date1)) {
            System.out.println("千禧年已经过去了");
        }
        
        LocalDate date2 = LocalDate.of(2020, 1, 1);
        if (now.isBefore(date2)) {
            System.out.println("2020年还未到来");
        }
        
    }

五、时区

  示例: 创建带有时区的日期时间

    Java 8不仅分离了日期和时间,也把时区分离出来了。现在有一系列单独的类如ZoneId来处理特定时区,ZoneDateTime类来表示某时区下的时间。

 public static void main(String[] args) {
        
        // 上海时间
        ZoneId shanghaiZoneId = ZoneId.of("Asia/Shanghai");
        ZonedDateTime shanghaiZonedDateTime = ZonedDateTime.now(shanghaiZoneId);
        
        // 东京时间
        ZoneId tokyoZoneId = ZoneId.of("Asia/Tokyo");
        ZonedDateTime tokyoZonedDateTime = ZonedDateTime.now(tokyoZoneId);
        
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        System.out.println("上海时间: " + shanghaiZonedDateTime.format(formatter));
        System.out.println("东京时间: " + tokyoZonedDateTime.format(formatter));
        
    }

六、格式化

  示例1: 使用预定义格式解析与格式化日期

public static void main(String[] args) {
        
        // 解析日期
        String dateText = "20180924";
        LocalDate date = LocalDate.parse(dateText, DateTimeFormatter.BASIC_ISO_DATE);
        System.out.println("格式化之后的日期=" + date);
        
        // 格式化日期
        dateText = date.format(DateTimeFormatter.ISO_DATE);
        System.out.println("dateText=" + dateText);
        
    }
 

  示例2: 日期和字符串的相互转换

 public static void main(String[] args) {
        
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        
        // 日期时间转字符串
        LocalDateTime now = LocalDateTime.now();
        String nowText = now.format(formatter);
        System.out.println("nowText=" + nowText);
        
        // 字符串转日期时间
        String datetimeText = "1999-12-31 23:59:59";
        LocalDateTime datetime = LocalDateTime.parse(datetimeText, formatter);
        System.out.println(datetime);
        
    }

七、相关类说明

Instant         时间戳
Duration        持续时间、时间差
LocalDate       只包含日期,比如:2018-09-24
LocalTime       只包含时间,比如:10:32:10
LocalDateTime   包含日期和时间,比如:2018-09-24 10:32:10
Peroid          时间段
ZoneOffset      时区偏移量,比如:+8:00
ZonedDateTime   带时区的日期时间
Clock           时钟,可用于获取当前时间戳
java.time.format.DateTimeFormatter      时间格式化类

八、前后端日期转换

//返回值处理格式化
@JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    
//参数定义 前端传递字符串
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date beginTime;

九、日期和date转换

String 转 Date

private Date getDateByString(String datetimeText) {
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    LocalDateTime hopeArriveTime = LocalDateTime.parse(datetimeText, formatter);
    ZoneId zoneId = ZoneId.systemDefault();
    ZonedDateTime zdt = hopeArriveTime.atZone(zoneId);
    return Date.from(zdt.toInstant());
}

Date 转 String

Date leaseStartTime = gardenCompany.getLeaseStartTime();
Date leaseEndTime = gardenCompany.getLeaseEndTime();
LocalDate startTime = leaseStartTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
LocalDate endTime = leaseEndTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
currentLease = startTime.format(formatter) + "-" + endTime.format(formatter);

十、两个日期相差时间

 public static void main(String[] args) {
        System.out.println(LocalDate.now().toEpochDay() - LocalDate.now().minusDays(5).toEpochDay());
    }

从打印攻击到视频重放:手把手用OULU-NPU训练你的第一个活体检测模型 本文详细介绍了如何使用OULU-NPU数据集训练活体检测模型,以应对打印攻击和视频重放等安全威胁。通过PyTorch框架,从环境准备、数据加载、预处理到模型架构设计,手把手教你构建一个高效的双流网络,结合CNN和LSTM技术,提升模型在多种攻击场景下的检测准确率。 阅读详情

相关推荐

STM32F103C8T6+I2C+DMA读取陀螺仪模块JY901S(硬件I2C

说明:1.本实验代码适用移植一切stm32f1系列;2.本实验使用的是外设资源硬件I2C2;3.本实验运用的是DMA单次模式,如果需要DMA的循环模式,请移步我的另一篇文章;4.本文章不提供陀螺仪校准教学,并是在没有校准陀螺仪情况下读取数据;5.本文章是作者的学习记录及心得,如有不足,欢迎指正。 总结:亲测stm32f103c8t6最小系统板通过片上外设资源I2C配合DMA读去陀螺仪模块jy901s偏航角有效。

anquanyuanqqadsy的博客 6173

Java8的新特性--新时间日期API

目录一、简单介绍二、常见用法示例2.1 LocalDateTime、 LocalDate、 LocalTime2.1.1 获取当前时间2.1.2 时间日期的比较和运算判断2.1.3 时间日期的转换2.2 Instant 时间戳2.3 ZoneId2.5 Duration、Period 计算时间间隔2.6 TemporalAdjuster 时间矫正器 Java8提供了一套全新的日期时间API,都位于java.time包下,这个包涵盖了所有处理日期date、时间time、日期/时间dateTime、时区zo

qianqian的博客 442

LlamaIndex 入门实战

LlamaIndex是一个“数据框架”,用于帮助构建LLM应用程序。它提供了各种工具,包括数据连接器,用于摄取现有数据源和数据格式(API,PDF,文档,SQL等),以及用于将数据结构化(索引,图形)以便与LLM轻松使用的方式。此外,LlamaIndex还提供了高级的检索/查询接口,可以输入任何LLM输入提示,并返回检索到的上下文和增强知识的输出。它还允许与外部应用程序框架(如LangChain,Flask,Docker,ChatGPT等)轻松集成。

AIGC搞起 1万+

localDateTime、Instant 、date间的关系

Date: 这也是一个本地的日期格式对象,和LocalDateTime不同,LocalDateTime提供了更丰富的处理时间的方法,同时LocalDateTime是线程安全的。Instant:这个一个默认为UTC时区的时间对象,和咱们平常的东八区相比,少了8个小时的时间。虽然没用过,但是觉得这个Instant不太会直接使用,作为一个中间的桥梁转换使用的应该较多。LocalDateTime 转 Date 、Instant转Date。Date转LocalDateTime、Date转Instant。

u014104653的博客 2031

C300 | 5680t | 新格林| AN5516 | 远程ONU升级指导

ONU的远程管理升级 1、ZTE C300 OLT : 1.1 环境拓扑: PC1(filezilla server)------(uplink_default-vlanID)OLT---------ONU | | mng1 1.2 配置部署: 1):PC1(filezilla server): IP:192.168.88.252 255.255.255.0 配置FTP-Server的用户名:gp...

Shelly的博客 3771

2025.03.14【读书笔记】|GWAS分析神器:BOLT-LMM工具介绍与快速安装

在生物信息学领域,全基因组关联分析(GWAS)已成为揭示遗传与疾病关系的强有力工具。BOLT-LMM作为一款专为大规模样本量设计的GWAS分析工具,将极大地提高研究人员的工作效率。大家好,今天我们来聊聊一个非常强大的生物信息学工具——BOLT-LMM。它是基于线性混合模型(LMM)的全基因组关联分析(GWAS)分析工具,通过快速的方差近似方法在计算效率上实现了显著的提升。BOLT-LMM的高效性能使其成为大规模样本GWAS分析的理想选择,它将进一步推动生物信息学和遗传学研究的发展。

1094

java8 localDateTime与 Date互相转化

1. 将LocalDateTime传化成 Date LocalDateTime ldt = LocalDateTime.now(); Date date =Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant()); 2. 将Date转化成 LocalDateTime Date date =new Date(); LocalDateTi...

xiaojuge的博客 392

《唤醒你的AI同事:WorkBuddy从零上手》000:介绍及目录

《唤醒你的AI同事:WorkBuddy从零上手》全书导览与总目录:000–043 共 44 篇,覆盖从环境搭建、对话基础到资料库、行业助手与多模态生成的入门实战。含完整篇目速查与编号直达,建议关注收藏。

LuckyHanMo的博客 606

java8 新日期api使用

date转localDate date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate() localDate转date Date.from(localDate.atTime(23,59,59).atZone(ZoneId.systemDefault()).toInstant()) localDate获取月份最后一天,返回localDate localDate.with(TemporalAdjusters.lastDayOfMonth())

weixin_44892460的博客 926

YOLOv8 改进涨点 | 模块即插即用 直接可用

在目标检测任务中,注意力机制能够帮助模型聚焦于图像中的关键区域,显著提升检测精度。。创建模块代码注册模块修改任务解析tasks.py创建YAML配置文件模块核心优势适用场景计算开销SOCA捕获二阶统计信息,增强通道间相关性需要精细特征区分的场景中等SK自适应多尺度核选择多尺度目标检测中等偏高显式特征聚集-分配机制全局上下文建模中等A2-Net双线性注意力,高效全局交互复杂场景理解中等偏高CrissCross线性复杂度全局上下文高分辨率输入,长距离依赖较低。

u012133341的博客 2259

一文让你轻松理解802.11ax RU的概念

RU

1042484520@qq.com(邮箱) 3368

java8日期操作

工作时用到的记录一下,方便再次使用时查找(跟着工作持续更新) 1.获取一个日期到此次日期的月底距离多少天 // 获取当前时间--也可以自定义时间然后转为LocalDateTime即可 LocalDateTime localDate = LocalDateTime.now(); // 获取此次日期的月底时间 LocalDateTime lastDayMonth = localDate.with...

jianguang01的博客 613

【QNX Hypervisor 2.2 用户手册】2.6 处理qvm终止

你可以注册通知,以在qvm进程实例退出时得到通知。这样你就可以采取相应的措施来响应这种终止事件。

从0到1,突破自己 1108

Java 8 日期操作

LocalDateTime:表示日期和时间,但不包含时区信息。LocalDate:仅表示日期,不包含时间和时区信息。LocalTime:仅表示时间,不包含日期和时区信息。ZonedDateTime:表示日期、时间和时区,适用于跨时区操作。Period:表示日期间隔,通常用于计算两个日期之间的差异。Duration:表示时间间隔,用于计算两个时间点之间的时长。

QAZ412803的博客 575

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

JAVA8之日期操作详解

package org.date; import java.time.DayOfWeek; import java.time.LocalDate; import java.time.Month; import java.time.temporal.ChronoField; /** * TODO : JAVA8 Date 操作详解 *...

dcy22899的博客 75

深度学习工具包 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")

Java 8 日期操作、解析与格式化

有的时候,你需要进行一些更加复杂的操作,比如,将日期调整到下个周日、下个工作日,或者是本月的最后一天。这时,你可以使用重载版本的with方法,向其传递一个提供了更多定制化选择的TemporalAdjuster对象,更加灵活地处理日期。对于最常见的用例,日期和时间API已经提供了大量预定义的TemporalAdjuster。你可以通过TemporalAdjuster类的静态工厂方法访问它们,如下所示。API 彻底革新了日期和时间的处理方式,告别了。的核心技巧,并提供可直接复用的代码示例。

技术交流,一起进步 861

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

JAVA8的日期操作

以前一直在用java7中的日期API,偶然看到java8中的API更好用,分享给大家。 参考链接感谢胖先森 Java 8 推出了全新的日期时间API,在教程中我们将通过一些简单的实例来学习如何使用新API。 新API基于ISO标准日历系统,java.time包下的所有类都是不可变类型而且线程安全。 示例1:Java 8中获取今天的日期 Java 8 中的 LocalDate 用于表示当天日期。和java.util.Date不同,它只有日期,不包含时间。当你仅需要表示日期时就用这个类。 package com

weixin_43990465的博客 242

Java8 的日期操作

罗列一下java8中对于日期的一些Api,以便在以后工作或练习中使用。 使用的是LocalDate、localTime和LocalDateTime这三个类对日期进行操作。 需要注意的是LocalDate、LocalTime和LocalDateTime是和String对象一样的,被final修饰,是不可变的。在对LocalDate或LocalTime进行操作后需要使用新的LocalDate、LocalTime或LocalDateTime去接收日期处理之后的返回值 package com.mywork.test

@起风了的博客 230

Java 8 日期时间操作类新特性

Java 8 的日期时间 API 提供了丰富的功能,解决了旧版 API 的不足。这些新类使用更加直观,支持不可变对象、方法链调用和时区操作,极大地提高了代码的可读性和开发效率。通过灵活运用这些类,可以轻松处理各种日期和时间的操作。最后欢迎关注我技术公众号,或者你有什么关于java 想了解的可以评论告诉我,我可以乐意为您单独出一篇详细讲解的Java移动技术栈。

qq_36534560的博客 765

JAVA java8 日期、时间操作(java8全新日期时间处理)

JAVA java8 日期、时间操作(java8全新日期时间处理)

qq_45844443的博客 630

Java 8 LocalDate 日期操作全攻略

Java 8 引入的 java.time.LocalDate 类用于处理不带时区的日期(年-月-日),遵循 ISO-8601 标准。主要特点包括: 不可变性,确保线程安全; 丰富的日期操作方法(加减、比较、格式化等); 智能处理月末日期等特殊情况。常用场景包括生日记录、日期计算等。通过 now()、of()、parse() 等方法创建实例,支持与旧日期 API 的转换。注意获取当前日期时隐含使用系统时区,但 LocalDate 本身不存储时区信息。

2301_80215285的博客 842

Java8 日期、时间操作

一、简介   在Java8之前,日期时间API一直被开发者诟病,包括:java.util.Date是可变类型,SimpleDateFormat非线程安全等问题。故此,Java8引入了一套全新的日期时间处理API,新的API基于ISO标准日历系统。      二、日期初识   示例1: 获取当天日期     Java 8中的 LocalDate 用于表示当天日期。和java.util.Date不同,它只有日期,不包含时间。 public static void main(String[] arg

花生福的博客 329

java 日期_Java8 日期、时间操作

一、简介在Java8之前,日期时间API一直被开发者诟病,包括:java.util.Date是可变类型,SimpleDateFormat非线程安全等问题。故此,Java8引入了一套全新的日期时间处理API,新的API基于ISO标准日历系统。二、日期初识示例1: 获取当天日期Java 8中的 LocalDate 用于表示当天日期。和java.util.Date不同,它只有日期,不包含时间。publi...

weixin_32822089的博客 74

java8 日期操作

java8 日期操作 SimpleDateFormat存在线程安全问题,解析错误: Caused by: java.lang.NumberFormatException: multiple points java8 日期操作新API:LocalDate,LocalTime,LocalDateTime类的实例都是不可变对象 DateTimeFormatter:时间格式化 TemporalAdjuster时间校正器 时区ZonedDate,ZonedTime,ZonedDateTime import c

靖节先生的博客 172

java 8 日期操作,真香

java 8 的日期类已经出来很长一段时间了,一直以来也没怎么用过,最近用到了感觉太好用了,真香。 java 8 在java.time提供了很多日期、时间相关类可以使用,这些类都是线程安全的,而且使用起来比Date日期类方便很多

做一个有思想的技术人 923

java8 日期、时间操作

Java8之前的日期和时间API,存在一些问题,最重要的就是线程安全的问题。这些问题都在Java8中的日期和时间API中得到了解决,而且Java8中的日期和时间API更加强大。传统时间格式化的线程安全问题 ...

jiqiren1994的博客 719
上一篇: Java获取IP工具类
下一篇: 用户更换部门 部门下员工数改变
codeLife1993
博客等级 码龄8年 23粉丝 60原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值