这里封装了一个类给大家直接上代码
package com.wz.orders.util;import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.SimpleTimeZone;
import java.util.TimeZone;public class GetTime {/*** 取北京时间,格式:yyyy-MM-dd HH:mm:ss* @return*/public static String getBeijingTime(){return getFormatedDateString(8);}/*** 取班加罗尔时间* @return*/public static String getBangaloreTime(){return getFormatedDateString(5.5f);}/*** 取纽约时间* @return*/public static String getNewyorkTime(){return getFormatedDateString(-5);}/*** 取澳大利亞时间* @return*/public static String getAustraliaTime(){String time =getFormatedDateString(10);SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");Date date=null;try {date = format.parse(time);} catch (ParseException e) {// TODO Auto-generated catch blocke.printStackTrace();}Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.add(Calendar.MINUTE, -2);return format.format(calendar.getTime());}/*** 根据时间获取天数* @param* @author songanshu* @date 2018年8月28日 下午1:16:42*/public static int getYear(String time) throws Exception {SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");Date date=format.parse(time);Calendar calendar = Calendar.getInstance();calendar.setTime(date);return calendar.get(Calendar.YEAR);}/*** 根据时间获取月份* @param* @author songanshu* @date 2018年8月28日 下午1:16:42*/public static int getMonth(String time) throws Exception {SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");Date date=format.parse(time);Calendar calendar = Calendar.getInstance();calendar.setTime(date);return calendar.get(Calendar.MONTH)+1;}/*** 根据时间获取天数* @param* @author songanshu* @date 2018年8月28日 下午1:16:42*/public static int getDay(String time) throws Exception {SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");Date date=format.parse(time);Calendar calendar = Calendar.getInstance();calendar.setTime(date);return calendar.get(Calendar.DAY_OF_MONTH);}/*** 根据时间获取小时数* @param* @author songanshu* @date 2018年8月28日 下午1:16:42*/public static int getHour(String time) throws Exception {SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");Date date=format.parse(time);Calendar calendar = Calendar.getInstance();calendar.setTime(date);return calendar.get(Calendar.HOUR_OF_DAY);}/*** 根据时间获取分钟数* @param* @author songanshu* @date 2018年8月28日 下午1:16:42*/public static int getMintue(String time) throws Exception {SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");Date date=format.parse(time);Calendar calendar = Calendar.getInstance();calendar.setTime(date);return calendar.get(Calendar.MINUTE);}/*** 根据时间获取秒数* @param* @author songanshu* @date 2018年8月28日 下午1:16:42*/public static int getSecond(String time) throws Exception {SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");Date date=format.parse(time);Calendar calendar = Calendar.getInstance();calendar.setTime(date);return calendar.get(Calendar.SECOND);}/*** 根据指定日期获取 指定日期的毫秒数* @param* @author songanshu* @date 2018年8月30日 下午5:24:11*/public static long getTimeLong(String time) throws Exception {SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");Date date=format.parse(time);Calendar calendar = Calendar.getInstance();calendar.setTime(date);return calendar.getTimeInMillis();}/*** 获取现在时间的毫秒数* @param* @author songanshu* @date 2018年8月30日 下午5:25:03*/public static long getNowTimeLong() throws Exception {long nowDate=getTimeLong(getBeijingTime());return nowDate;}/*** 初始化期数  格式  yyyyMMddhhmm* @param* @author songanshu* @date 2018年8月28日 下午1:17:11*/public static String  serializeSection(String time){String time0=time.substring(0,time.lastIndexOf(":"));String time1=time0.replaceAll("-"," ");String time2=time1.replaceAll(":"," ");String time3=time2.replaceAll(" ","");return time3;}/*** timeZoneOffset原为int类型,为班加罗尔调整成float类型* timeZoneOffset表示时区,如中国一般使用东八区,因此timeZoneOffset就是8* @param timeZoneOffset* @return*/public static String getFormatedDateString(float timeZoneOffset){if (timeZoneOffset > 13 || timeZoneOffset < -12) {timeZoneOffset = 0;}int newTime=(int)(timeZoneOffset * 60 * 60 * 1000);TimeZone timeZone;String[] ids = TimeZone.getAvailableIDs(newTime);if (ids.length == 0) {timeZone = TimeZone.getDefault();} else {timeZone = new SimpleTimeZone(newTime, ids[0]);}SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");sdf.setTimeZone(timeZone);return sdf.format(new Date());}public static String getFormatedDateStringorder(float timeZoneOffset,int  type){if (timeZoneOffset > 13 || timeZoneOffset < -12) {timeZoneOffset = 0;}int newTime=(int)(timeZoneOffset * 60 * 60 * 1000);TimeZone timeZone;String[] ids = TimeZone.getAvailableIDs(newTime);if (ids.length == 0) {timeZone = TimeZone.getDefault();} else {timeZone = new SimpleTimeZone(newTime, ids[0]);}if(type==1){SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdHHmmss");sdf.setTimeZone(timeZone);return sdf.format(new Date());}else{long currentTime = System.currentTimeMillis() + 30 * 60 * 1000;SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/d HH:mm:ss");sdf.setTimeZone(timeZone);return sdf.format(new Date(currentTime));}}/*** 获取多少小时的时间* @param 多少小时* @author songanshu* @date 2018年8月28日 下午1:17:11*/public static String  getHourDate(int hour){SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");Date date=new Date();//取时间Calendar calendar=new GregorianCalendar();calendar.setTime(date);calendar.add(calendar.HOUR, hour);date=calendar.getTime();return sdf.format(date);}/*** 指定时间与现在时间的差* @param* @author songanshu* @date 2018年10月21日 下午4:25:18*/public static long getTimeDifference(String overTime) {//time 时间,dtime 倒计时(单位秒)SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");Date nowDate= new Date();long second = 0;try {Date overDate= dfs.parse(overTime);long over=overDate.getTime();long sy=over-nowDate.getTime();if(sy>=0){second= sy/ 1000;}else{second = 0;}} catch (Exception ex) {ex.printStackTrace();}return second;}/*** 时间差* @param* @author songanshu* @date 2018年10月21日 下午4:25:18*/public static long getTimeCha(String overTime) {//time 时间,dtime 倒计时(单位秒)SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");Date nowDate= new Date();long second = 0;try {Date overDate= dfs.parse(overTime);long over=overDate.getTime();long sy=nowDate.getTime()-over;second= sy/ 1000;} catch (Exception ex) {ex.printStackTrace();}return second;}
}

根据自己的需求获取相应的时间即可

java获取北京时间系统时间全球各地时间。相关推荐

  1. Java获取指定年月的开始时间和结束时间

    文章目录 Java获取指定年月的开始时间和结束时间 Java获取指定年月的开始时间和结束时间 // 获取指定年指定月的开始天数和结束天数public static Map<String,Date ...

  2. java获取电脑配置_使用Java获取cao作系统和硬件信息

    距离上一次写博客已经过去2个半的月份了,也是工作忙,也是懒,也是在积攒文章吧,反正就是许久没有写了,本次分享一个用Java获取cao作系统和硬件信息的组件,在十一假期之前就准备分享的,然这些详细的参数 ...

  3. java获取Win系统日志最后(最新)开关机时间记录等

    java获取Win系统日志开关机记录等 java实现代码在后面,没耐心看的小伙伴请玩后面划拉 今天看到一个比较有意思的需求. java实现获取win系统最近一次关机时间. 这里先谈一下解决思路,有问题 ...

  4. C#编程练习(03):北斗时间系统、GPS时间系统及其与UTC时间系统之间的转换

    需求说明:北斗周-周内秒转化为日历时,转化为UTC时,转化为GPS周周内秒 GPS周-周内秒转化为日历时,转化为UTC时,转化为北斗周-周内秒 设计示意图: 源代码: using System; us ...

  5. java获取和设置系统变量(环境变量)

    一.Java获取环境变量 Java 获取环境变量的方式很简单: System.getEnv()  得到所有的环境变量 System.getEnv(key) 得到某个环境变量 Map map = Sys ...

  6. matlab仿真采样时间,系统中的采样时间 - MATLAB Simulink - MathWorks 中国

    纯离散系统 纯离散系统完全由离散模块组成,可以使用固定步长或可变步长求解器进行建模.要对离散系统进行仿真,需要仿真器在每个采样时间点执行一个仿真步.对于多速率离散系统 - Simulink® 以不同速 ...

  7. java 获取及修改系统变量

    设置系统变量 设置由指定键指示的系统属性. 首先,如果安全管理器存在SecurityManager.checkPermission方法是使用PropertyPermission(key,"w ...

  8. Java获取当前的系统时间

    一. 获取当前系统时间和日期并格式化输出: import java.util.Date; import java.text.SimpleDateFormat; public class NowStri ...

  9. java获取一天的开始时间和结束时间

    java8 LocaleDateTime 获取 public static void main(String[] args) {LocalDateTime date = LocalDateTime.n ...

最新文章

  1. 自学PHP教程之每天学一个函数(一):isset()
  2. 学霸大佬整理,超全 Python 学习路线图(附工具+视频+书籍+面试)
  3. wpf window 不执行show 就不能load执行_Numpy反序列化命令执行漏洞分析(CVE-2019-6446)附0day...
  4. python入门html_python-html入门
  5. 侯宁:不该捞的别去捞 踏空不是浪费时间
  6. 八数码c语言编程深度搜索,广度优先搜索解 八数码, 求意见, 求bug/
  7. java矩阵类_151-矩阵类
  8. 请不要再使用判断进行参数校验了
  9. Python笔记(3) Python入门
  10. css入门自学笔记1
  11. pytorch---model.train()和model.eval()用法和区别
  12. Unity3d知识点
  13. 有关错误:buffer i/o error on device fd0,logical block 0
  14. Arcface 总结
  15. 儿科常见疾病的中成药疗法
  16. 鸿蒙系统充电慢,数据线充电慢怎么解决
  17. windows 搭建eureka注册中心
  18. Java用JFrame、JPanel、Graphics绘图案例讲解
  19. Java实现会员和非会员,如何选择会员和非会员功能?
  20. MP3音频编解码芯片 VS1053B-L

热门文章

  1. LabVIEW调试技巧
  2. 《程序是怎样跑起来的》摘录
  3. C语言 模拟按键操作
  4. CORBA 架构体系指南(通用对象请求代理体系架构)
  5. android开发手顺3--Package name must have at least two identifiers 原因及解决方法
  6. oracle中栓锁,特定的闩锁和互斥场景
  7. 在这领工资,一辈子别想取媳妇了!
  8. 京东到家定位系统演化
  9. 什么是私域流量?如何运营?
  10. mv单位是什么意思_ayawawa经常说的pu MV是什么意思 怎么mv是什么意思算