JAVA randomly generates file names: current year, month, day, hour, minute and second + five-digit random number

The code is as follows: package cn.gov.csrc.util;import java.text.SimpleDateFormat;import java.util.Date;import java.util.Random; public class RandomUtil { /** * Generate a random file name: current year, month, day, hour, minute and second + five-digit random number * * @return */ public static String getRandomFileName() { SimpleDateFormat simpleDateFormat; simpleDateFormat = new SimpleDateFormat(“yyyyMMdd”); Date date = new Date (); String str = simpleDateFormat.format(date); Random random = new Random(); int rannum = (int) (random.nextDouble( ) * (99999 – 10000 + 1)) + 10000;// Get a 5-digit random number return rannum + str;// Current time } public static void main( String[] args) { String fileName = RandomUtil.getRandomFileName(); System.out.println(fileName);//8835920140307 }}

Time operation (JavaScript version)—page display format: year, month, day, morning, afternoon, hour, minute, second, day of the week

java gets the current time accurate to milliseconds, java gets the year, month, day, hour, minute, second, and millisecond

package com.excel; Import Java.text.simple date format; import java.util .Calendar; import java.util.Date; Public class test{ publicstaticvoidmain (stringaxdxnargs) throws Exception { ). calendar now=calendar.getinstance (; date=new date (; stringdatenowstr=SDF.format (date; stringstr=’ 2012-1-1317336026336033 ‘; //Same format as defined in sdf above datetoday=SDF.parse(str); } } Get a date on the day of the week Calendar c=Calendar.getInstance (; c. settime (format. parse (2014-12-8) ); int dayForWeek=0; if(c.get (calendar.day_of_week )==1) { dayForWeek=7; } else { dayforweek=c.get (calendar.day _ of _ week )- 1; }

Divide days into different parts of year, month, day, hour. Java

Is there a way to divide the number of days calculated by calculating the difference between two dates into different parts, for example for 364 days it would be: 0 years, 11 months, 30 days, hours, minutes etc.I thought using logical operators like % and / would work, but since different months have different numbers of days, and some years are leap years, I’m not sure how to do that. Any help would be greatly appreciated .My code: import java.util.*;public class CleanDate { public static void main(String[ ] args) { Calendar cDate = GregorianCalendar.getInstance(); cDate.set(2011, 0, 31, 00, 00, 00); Date date1 = cDate.getTime(); Date date2 = new Date(); Calendar calendar1 = Calendar.getInstance(); Calendar calendar2 = Calendar.getInstance(); calendar1.setTime(date1); calendar2.setTime( date2); long milliseconds1 = calendar1.getTimeInMillis(); long milliseconds2 = calendar2.getTimeInMillis(); long diff = milliseconds2 – milliseconds1; long diffSecOnds= diff / 1000; long diffMinutes = diff / (60 * 1000); long diffHours = diff / (60 * 60 * 1000); long diffDays = diff / (24 * 60 * 60 * 1000); System. out.println(“Time in minutes: ” + diffMinutes + ” minutes.”); System.out.println(“Time in hours: ” + diffHours + ” hours.”); System.out. println(“Time in days: ” + diffDays + ” days.”); }} Solution:…

Java-Calculate the first and last day of the week, month, and year for any date

package com.slk.utils; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.HashMap; import java.util.Map; /** * This module can automatically calculate the first and last days of the week, month, and year corresponding to the current date, and can directly specify the current date as any date. * * @author Administrator * */ public class DateTerminator { // Get the upper and lower bounds of the week of the current date public final static int CURRENT_WEEK = 0; // Get the upper and lower bounds of the previous week on the current date public final static int LAST_WEEK = 1; // Get the upper and lower bounds of the month where the current date is located public final static int CURRENT_MOnTH= 2; // Get the upper and lower bounds of the previous month on the current date public final static int LAST_MOnTH= 3; // Get the upper and lower bounds of the month where the current date is located public final static int CURRENT_YEAR = 4; // Get the upper and lower bounds of the previous month on the current date public final static int LAST_YEAR = 5; /** * Calculate the upper and lower bounds of the…

Java outputs the current date (year, month, day, hour, minute, second, millisecond)

package test.remote.tools.combine; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class TestOutDate { public static void main(String[] args) { //method 1 Calendar nowtime = new GregorianCalendar(); String strDateTime=”[“+String.format(“%04d”, nowtime.get(Calendar.YEAR))+”/”+ String.format(“%02d”, nowtime.get(Calendar.MONTH))+”/” + String.format(“%02d”, nowtime.get(Calendar.DATE))+” ” + String.format(“%02d”, nowtime.get(Calendar.HOUR))+”:” + String.format(“%02d”, nowtime.get(Calendar.MINUTE))+”:” + String.format(“%02d”, nowtime.get(Calendar.SECOND))+”.” + String.format(“%03d”, nowtime.get(Calendar.MILLISECOND))+”]”; System.out.println(strDateTime); //method 2 String msg=””; Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat(“YYYY/MM/dd HH:mm:ss.SSS”); msg+=”[“+sdf.format(date)+”]”; System.out.println(msg); } } Run results: [2013/08/09 05:54:32.578] [2013/09/09 17:54:32.625]

How to get the year, month, day, hour, minute and second using javaDate

The following editor will bring you an implementation method of obtaining year, month, day, hour, minute and second in java Date. The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor and take a look How to get the year, month, day, hour, minute and second using Java Date package com.util; import java.text.DateFormat; import java.util.Calendar; import java.util.Date; public class Test { public void getTimeByDate(){ Date date = new Date (); DateFormat df1 = DateFormat.getDateInstance();//Date format, accurate to the day System.out.println(df1.format(date)); DateFormat df2 = DateFormat.getDateTimeInstance();//Can be accurate to the hour, minute, and second System.out.println(df2.format(date)); DateFormat df3 = DateFormat.getTimeInstance();//Only display hours, minutes and seconds System.out.println(df3.format(date)); DateFormat df4 = DateFormat.getDateTimeInstance (DateFormat.FULL,DateFormat.FULL); //Display date, week, morning and afternoon, time (accurate to seconds) System.out.println(df4.format(date)); DateFormat df5 = DateFormat.getDateTimeInstance(DateFormat.LONG ,DateFormat.LONG); //Display date, morning and afternoon, time (accurate to seconds) System.out.println(df5.format(date)); DateFormat df6 = DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.SHORT); //Display date, morning and afternoon, time (accurate to minutes) System.out.println(df6.format(date)); DateFormat df7 = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM); //Display date and time (Accurate to minutes) System.out.println(df7.format(date)); } public void getTimeByCalendar(){ Calendar cal = Calendar.getInstance(); int year = cal.get(Calendar.YEAR);//Get Year int mOnth=cal.get(Calendar.MONTH);//Get the month int day=cal.get(Calendar.DATE);//Get the day int hour=cal.get(Calendar.HOUR);//Hour int minute =cal.get(Ca[email protected]~马网lendar.MINUTE);//minutes…

Java calculates the difference between year, month, day and number of days

This article has two small programs: input two years, months and days, and this program outputs the number of days between the two times. The first one can report an error for inappropriate time input by the user, and the second one is a simplified version of the first program that will not report an error. Only after the user enters the correct date can the correct number of days difference be obtained. Date-day difference calculation program: import java.util.Scanner; public class Time3 { public static void main(String[]args){ Scanner in=new Scanner(System.in); System.out.println(“Input the present time (Format:year(Press enter) month(Press Enter) day(Press Enter)):”); //Y1, M1, D1 and Y2, M2, D2 respectively represent “the current year, month and day” and “previous to the current specified year, month and day”, which are required for calculation, among which Y1 and Y2 are defined as double type double Y1=in.nextInt(); int M1=in.nextInt(); while(M112){ System.out.println(“The “+M1+”th month dosen’t exist,please try again”); M1=in.nextInt();}//Make sure the entered month is an integer from 1-12 int D1=in.nextInt(); while(D1>MaxDay(Y1,M1)||D1Y1){ System.out.println(“the former year can’t be later than the present time,please try again”); Y2=in.nextInt();} int M2=in.nextInt(); while(M212){ System.out.println(“The “+M2+”th month dosen’t exist,please try again”); M2=in.nextInt(); if(Y2==Y1){ while(M2>M1){ System.out.println(“the former month in the same year can’t be…

Java implementation to obtain the current year, month, day, hours, minutes, seconds and milliseconds

First click start and enter regedit in the lower left corner. Right-click HKEY_CURRENT_USER, click Find, enter NoRecentDocsHistory and find NoRecentDocsHist on the right… Spring Learning Notes – MVC series of articles, there are 3 articles explaining returning json data, they are: [Spring study notes – MVC-3] SpringMVC returns Json data – method 1: http://www … CODESOFT is a powerful, flexible and convenient label barcode design and printing software. When using CODESOFT to design and print labels, sometimes it is necessary to adjust the width of the line in the barcode due to reasons such as printing accuracy or scanning clarity, that is, adjusting the barcode line width. .This article, editor… 1. Simple example (1). Define an attrs.xml file under the res/values ​​file? xml version= 1.0 encoding= utf-8&quot… Link: http://blog.sina.com.cn/s/blog_614f347b0101egah.html Code: import java.awt.*; import java. awt.even… Automatic order issuing, automatic evaluation, automatic commenting, automatic promotion of WeChat mini program automatic operator WeChat mini program automatic operator (let your WeChat mini program and public account have zero operating costs , 24-hour fully automatic operation) We will customize and develop based on your WeChat official account or WeChat applet with certain AI intelligence… Foreword, I haven’t updated my blog for a long time,…

5bd40f9fce2c99ef8a93cd3ba385d15d.  png

javadate only retains the year, month and day_Java date and time API series 16Jdk8API class, java date calculation 3, attribute modification of the year, month, day, hour, minute and second…

Through the LocalDate source code analysis of the new date and time API class in the Java Date and Time API Series 8—–Jdk8 in the java.time package, it can be seen that the java8 design is very good and the implementation interface Temporal, TemporalAdjuster, ChronoLocalDate, etc. have very rich methods. For example, some methods of :LocalDateTime:: Contains the attribute value modification of year, month, day ,hour, minute and second. If you want to modify the attribute value in Date, you must use Calendar. Now by converting Date to LocalDateTime, it is very convenient to modify the thread-safe year, month, day, hour, minute, second and other attribute values. // modify property Test class: @Test Output: Wed Source code address: https://github.com/xkzhangsan/xk-time​github.com

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索