这篇文章将为大家详细讲解有关利用Java怎么获取指定的时间,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。具体如下:package getBeforeHourDemo;import java.
这篇文章将为大家详细讲解有关利用Java怎么获取指定的时间,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
具体如下:
package getBeforeHourDemo;import java.text.SimpleDateFORMat;import java.util.Calendar;//获取当前时间,指定前面多少小时的时间 //返回格式YYYYMMDDHHMMSS public class getBeforeHourTime { public static String getBeforeByHourTime(int ihour){ String returnstr = ""; Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - ihour); SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); returnstr = df.format(calendar.getTime()); return returnstr; } public static void main(String[] args) { String beforetime=getBeforeByHourTime(2); System.out.println(beforetime); }}
--结束END--
本文标题: 利用Java怎么获取指定的时间
本文链接: https://www.lsjlt.com/news/223993.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0