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..

i.e

200801280100922

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..

Thanks!
jedistarAsked:
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.

ysnkyCommented:
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);
		sdf.setTimeZone(TimeZone.getDefault()); 
		String currentTime = sdf.format(cal.getTime());
		
		String myStr = currentTime + Integer.toString(i);
		
		System.out.println(myStr);

Open in new window

0

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
ysnkyCommented:
>>How do i put it in a label field and also submit it as a hidden input type..
in jsp;

<p><%=myStr%></p>
<input type=hidden name="my_hidden" value="<%=myStr%>">
0
jedistarAuthor Commented:
Sorry I forgot to include time as well after the date, how could i do that?
0
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.

ysnkyCommented:
so replace
String DATE_FORMAT = "yyyyMMddHHmm";
with
String DATE_FORMAT = "yyyyMMddHHmmss";


"HHmmss"  for time

for more;
http://www.exampledepot.com/egs/java.text/FormatDate.html
0
ysnkyCommented:
with milisecond try this;
String DATE_FORMAT = "yyyyMMddHHmmssS";
0
jedistarAuthor Commented:
Thanks!
0
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.