JSP - Create a Date String with Random numbers

Hi guys,

I have a .jsp file in tomcat which has a form. How do i create a string which contains date and random numbers..



2008 = year
01 = month
28 = day
0100 = time in 24 hr clock
922 = random 3 numbers

How do i put it in a label field and also submit it as a hidden input type..

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

here it is;
		Random rand = new Random();	    
	    // Random integers
	    int i = rand.nextInt(899) + 100;
		Calendar cal = Calendar.getInstance(TimeZone.getDefault()); 
		String DATE_FORMAT = "yyyyMMddHHmm"; 
		java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(DATE_FORMAT);
		String currentTime = sdf.format(cal.getTime());
		String myStr = currentTime + Integer.toString(i);

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
>>How do i put it in a label field and also submit it as a hidden input type..
in jsp;

<input type=hidden name="my_hidden" value="<%=myStr%>">
jedistarAuthor Commented:
Sorry I forgot to include time as well after the date, how could i do that?
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

so replace
String DATE_FORMAT = "yyyyMMddHHmm";
String DATE_FORMAT = "yyyyMMddHHmmss";

"HHmmss"  for time

for more;
with milisecond try this;
String DATE_FORMAT = "yyyyMMddHHmmssS";
jedistarAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java App Servers

From novice to tech pro — start learning today.