System.currentTimeMillis();

Java 日期和时间(一)System.currentTimeMillis()和Date类 如果重复调用此方法,则可能一段时间内返回相同的值,然后突然跳跃 10-20-30 毫秒或更多。这样,由大粒度时间值(不会每毫秒改变的值)引起的不准确性就会被拉平。java.sql.Date 扩展自 java.util.Date,所以任何能用 java.sql.Date 做的事情java.util.Date 也可以。这个类是Java 的第一个日期类之一,截至目前为止这个类的很多方法都已经被弃用,取而代之的是。获取测量的操作之前和之后的时间,并计算时间差。只保留其所代表的日期的日期,而不保留时间。 阅读详情

1、  意义:

currentTimeMillis()返回以毫秒为单位的当前时间,返回的是当前时间与协调世界时 1970 年 1 月 1 日午夜之间的时间差(以毫秒为单位测量)。注意,当返回值的时间单位是毫秒时,值的粒度取决于基础操作系统,并且粒度可能更大。例如,许多操作系统以几十毫秒为单位测量时间。

2、  用处:

(1)      用来测试程序的运行时间:

publicclass TestTime{

           public static void main(String[] args){

        String str = new String("0");

        long time1 =System.currentTimeMillis();

        for(int i=0;i<10000;i++){

            str += i;

        }

        long time2 =System.currentTimeMillis();

        System.out.println("for循环共用了" + (time2 - time1) + "毫秒。");

    }

}

(2)      控制线程时间,刷新屏幕频率:
time1 = System.currentTimeMillis();
你所运行的程序。。。
time2 = System.currentTimeMillis();
if (time2 - time1 < 60) {
try {
Thread.sleep(60 - (time2 - time1));
} catch (InterruptedException e) {
}
}

(3)      生成不重复的文件名:

public String getName(){

     Stringdate1 = null;

     SimpleDateFormatsdf1 = new SimpleDateFormat("yyyyMMddHHmmssSSS");

     date1= sdf1.format(new Date(System.currentTimeMillis()))+".txt";

     return date1;

}

【项目实战】System.currentTimeMillis ,用于获取当前时间的时间戳。 时间戳是从 1970 年 1 月 1 日 00:00:00 UTC(协调世界时间)开始计算的。如果您需要将时间戳转换为日期格式,可以使用。,是 Java 中的一个方法。,用于获取当前时间的时间戳。 阅读详情

相关推荐

Java中获取系统时间的currentTimeMillis函数及其应用解析

在上述示例中,我们首先记录了代码块的开始时间,然后在代码块执行完毕后记录了结束时间。通过计算开始时间和结束时间的差值,我们可以得到代码的执行时间。函数还可以用于性能测试和计时器的实现。我们可以在代码的不同位置调用该函数,并计算时间差来评估代码的执行效率。上述代码将获取当前系统时间的毫秒数,并将其打印输出。通过这种方式,我们可以获取一个唯一的时间戳,用于记录事件发生的时间或计算时间间隔。返回的是当前系统时间的纳秒数,精度更高,适用于性能测试等场景。类提供了更多关于日期和时间的操作方法,但在获取当前时间方面,

CyberLynxX的博客 3891

System.currentTimeMillis()

System.currentTimeMillis()计算方式与时间的单位转换 一、时间的单位转换 1秒=1000毫秒(ms) 1毫秒=1/1,000秒(s) 1秒=1,000,000 微秒(μs) 1微秒=1/1,000,000秒(s) 1秒=1,000,000,000 纳秒(ns) 1纳秒=1/1,000,000,000秒(s) 1秒=1,000,000,000,000 皮秒(ps) 1皮秒...

全盛 4万+

python爬虫自动下载网页链接

需求分析 今天遇到一个简单的需求,需要下载澳大利亚电力市场NEM日前市场的发电商报价数据(http://nemweb.com.au/Reports/Current/Next_Day_Offer_Energy/),页面观感是这样的: Ctrl + F 一下,看到一共有395个zip链接。于是就想着用python爬虫自动下载。这个网页很简单,没有验证码,甚至不需要登录,因此自动下载的pytho...

da_kao_la的博客 1万+

System.currentTimeMillis()用法及其计算方式与时间的单位转换

System.currentTimeMillis()的作用是返回当前的计算机时间,格式为当前计算机时间和GMT时间(格林威治时间)1970年1月1号0时0分0秒所差的毫秒数 时间的单位转换 1秒=1000毫秒(ms) 1分钟=60秒 1小时=60分钟=3600秒 用途一:计算某任务 耗费的毫秒 //开始时间 long start = System.currentTimeMillis(); for (int i = 0; i < 5; i++) { T.

Nothing is impossible to a willing heart. 2万+

编程小白的自学笔记四(正则表达式模块search函数)

本文仅仅简单介绍了search的使用,供小白学习探讨。

m0_49914128的博客 2320

【数学基础】基于欧拉角表达的旋转顺序

欧拉角旋转顺序

FalschxMico 1384

System.currentTimeMillis();

用这个取得当前时间System.currentTimeMillis();在程序的开始处取一下,然后在程序退出前再取一下,两次取得的值相减就是程序运行的时间,单位是毫秒。 ...

记录 231

Vivado FFT IP核配置与实战:FPGA信号处理硬件加速指南

快速傅里叶变换(FFT)是数字信号处理(DSP)中的核心算法,用于将时域信号转换到频域进行分析。其原理基于离散傅里叶变换(DFT),通过蝶形运算的分解与复用,大幅降低了计算复杂度。在工程实践中,软件实现的FFT难以满足高速实时处理的需求,因此硬件加速方案至关重要。FPGA凭借其并行架构和可定制性,成为实现高性能FFT的理想平台。通过集成专用的FFT IP核,如Vivado中的Pipelined Streaming I/O架构,可以构建流水线化的计算引擎,实现极低延迟和高吞吐量的连续数据流处理。这种硬件方案特

weixin_42536863的博客 646

编码中的小技巧System.currentTimeMillis();

System这个类下面有一个CurrentTimeMillis()方法。 这个方法表示获取到当前计算机的时间,格式为当前计算机时间和GMT时间所差的毫秒数。 我们可以在即将运行的代码开始处记录这个时间,并在代码运行结束处记录一个时间,并将两者做减法操作就能知道这段代码所消耗的时间来确定是否可以进一步优化代码。 public void Test(HttpServletReques...

SuperAE86的博客 455

Openclaw错误排查及解决方案之:Something went wrong while processing your request. Please try again.

Openclaw错误排查及解决方案之:Something went wrong while processing your request. Please try again.

多媒体编程、网络编程、系统编程、网络安全编程、驱动编程 3787

【HAL库】STM32CubeMX开发----STM32F407----ETH+LAN8720A+LWIP----ping通

本次实验以芯片为MCU,使用25MHz外部时钟源。以太网PHY层芯片为LAN8720A,由MCU引脚PA8提供时钟。

MQ0522的博客 4843

java测试方法运行时间 System.currentTimeMillis();

测试: 效果: System.currentTimeMillis(); currentTimeMillis()返回以毫秒为单位的当前时间,返回的是当前时间与协调世界时 1970 年 1 月 1 日午夜之间的时间差(以毫秒为单位测量)。注意,当返回值的时间单位是毫秒时,值的粒度取决于基础操作系统,并且粒度可能更大。例如,许多操作系统以几十毫秒为单位测

gao_chun 7万+

为什么 CL_DEMO_OUTPUT 不能用于生产用途:不仅是 demo 标签那么简单

摘要:CL_DEMO_OUTPUT 虽能快速展示ABAP数据,但存在严重生产风险:1) 官方定位为示例工具,不承诺兼容性与支持;2) 非Released API,云环境直接不可用;3) 依赖SAP GUI,缺乏日志关键特性;4) 存在版本漂移、类型限制、性能隐患及安全缺口。典型事故案例包括后台Job崩溃、Gateway链路污染和云迁移失败。生产环境应改用结构化日志(如SLG1)或稳定API输出,避免将调试工具误作工程方案。(149字)

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 131

System.currentTimeMillis() 和 System.nanoTime();

做开发的时候遇到一个问题,由于对状态栏进行了重写,在零点几毫秒内的反复点击不再进行处理,用到了这样一个判断                         long time = System.currentTimeMillis();                 //Log.d("test","time====>"+time);                 if (time

liuhanhan512的专栏 1069

华为OD 面试手撕代码真题【岛屿的周长】

0代表水,1代表陆地,岛由陆地组成且岛内不允许有湖,让你求岛的周长。

MISAYAONE的博客 8417

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

获取方法执行时间 -System.currentTimeMillis();

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_33894992的博客 803

深度学习工具包 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 · 计算方法的执行时间:System.currentTimeMillis();方法

Java · 计算方法的执行时间:System.currentTimeMillis();方法

qq_43118674的博客 282

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

上一篇: 严重: Exception starting filter struts2
下一篇: Java this、super的用法
funi16
博客等级 码龄16年 55粉丝 56原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值