练习.获取当前时间

package com.java7.showcurrenttime.main;
/*
 * System.currentTimeMillis返回从GMT(格林威治标准时间) 1970年1月1日00:00:00开始到当前时刻的毫秒数
 * 因为1970年是UNIX正式发布的时间,所以这一时间也称为UNIX时间戳(UNIX epoch)
 */
public class ShowCurrentTime {
    public static void main(String[] args) {
        // Obtain the total milliseconds since midnight, Jan 1, 1970
        long totalMilliseconds = System.currentTimeMillis();

        long totalSeconds = totalMilliseconds / 1000;
        // 通过totalSeconds % 60得到当前的秒数
        long currentSecond = totalSeconds % 60;

        long totalMinutes = totalSeconds / 60;
        // 通过totalMinutes % 60得到当前分钟数
        long currentMinute = totalMinutes % 60;

        long totalHours = totalMinutes / 60;
        // 通过totalHours % 24得到当前的小时数
        long currentHour = totalHours % 24 + 8;

        System.out.println("当前时间是: " +
                currentHour + ":" + currentMinute + ":" + currentSecond + " GMT+8");
    }
}
时间: 2024-08-25 14:38:24

练习.获取当前时间的相关文章

MySQL时间函数-获取当前时间-时间差

MySQL中获取当前时间为now(),不同于sqlserver getdate(). SQLServer转MySQL除变化top 1 -> limit 1之后报错: select 1 from record_visitor where visitor_ip='' and datediff(mi,visitor_time,getdate())<=30 limit 1 [Err] 1582 - Incorrect parameter count in the call to native func

iOS 获取当前时间以及计算年龄(时间差)

获取当前时间 NSDate *now = [NSDate date]; NSLog(@"now date is: %@", now); NSCalendar *calendar = [NSCalendar currentCalendar]; NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarU

Js获取当前日期时间+日期印证+判断闰年+日期的天数差+日期格式化+JS判断某年某月有多少天

Js获取当前日期时间+日期验证+判断闰年+日期的天数差+日期格式化+JS判断某年某月有多少天 字符串转日期型+Js当前日期时间+日期验证+判断闰年+日期的天数差+日期格式化+日期所在年的第几周 日期时间脚本库方法列表Date.prototype.isLeapYear 判断闰年Date.prototype.Format 日期格式化Date.prototype.DateAdd 日期计算Date.prototype.DateDiff 比较日期差Date.prototype.toString 日期转字符

Javascript获取服务器时间

Javascript是运行在客户端的脚本,我们一般都用new Date()来获取当前时间,但是得到的是客户端的时间,客户端时间是随意更改的,如果要做一个产品发布倒计时的话,客户端时间一改,就要闹笑话了.业务中需要用到服务器时间的场景还有很多,那么仅仅通过js怎么拿到服务器时间呢?事实上,只需要一个ajax请求就搞定,通过读取XMLHttpRequest对象的请求头里面的时间戳得到当前服务器时间! 原理就是这么简单:通过ajax向服务器发送请求,当服务器收到请求后即可读取请求头的时间戳了,不管请求

PHP获取当前时间、时间戳的各种格式写法汇总

今天写下php中,如何通过各种方法 获取当前系统时间.时间戳,并备注各种格式的含义,可灵活变通.1.获取当前时间方法date()很简单,这就是获取时间的方法,格式为:date($format, $timestamp),format为格式.timestamp为时间戳–可填参数.2.获取时间戳方法time().strtotime()这两个方法,都可以获取php中unix时间戳,time()为直接获取得到,strtotime($time, $now)为将时间格式转为时间戳,$time为必填.清楚了这个

javascript获取当前时间

? //时间设置 <script type="text/javascript"> <!-- var myDate = new Date();     myDate.getYear();      //获取当前年份(2位)     myDate.getFullYear(); //获取完整的年份(4位,1970-????)     myDate.getMonth();      //获取当前月份(0-11,0代表1月)     myDate.getDate();     

实例365(6)---------DateTime.ToString格式化日期,使用DateDiff方法获取日期时间的间隔数

一:DateTime.ToString格式化日期,截图 二:代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace TmrFormat { public part

iOS 获取当前时间格式化字符串

iOS 获取当前时间格式化字符串 太阳火神的美丽人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS.Android.Html5.Arduino.pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作. // 获取系统当前时间 NSDate * date = [NSDate date]; NSDateFormatt

js 的date的format时间,获取当前时间,前一天的日期

Date.prototype.Format = function (fmt) { //author: meizz var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "h+": this.getHours(), //小时 "m+": this.getMinutes(), //分 "s+": this.getSeconds()

LR获取当前时间

Lr_save_datetime,将当前日期时间保存到一个参数里. 常见场景:系统稳定性拨测时在脚本加入该函数(结合if-else使用),拨测失败时自动打印当前时间,为拨测失败问题排查提供时间切入点. //获取当前时间并保存到变量aTime中 lr_save_datetime("现在的时间是 %Y-%m-%d %H-%M-%S", DATE_NOW+TIME_NOW, "aTime"); //打印变量aTime的值 lr_error_message(lr_eval_