lvandevender
asked on
unique number generator
How do you create a javascript number generator using the year,month,day, hour, and minute set on my computer?
And if possible, how do i format this number to be 10 characters in length with the format of YYMMDDHHmm?
Y=year,M=month,D=day,H=hou r,m=minute
And if possible, how do i format this number to be 10 characters in length with the format of YYMMDDHHmm?
Y=year,M=month,D=day,H=hou
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
slight modification to pravin's code:
str += make2digit(dt.getDate());
str += make2digit(dt.getDate());
Thanks raj3060 for pointing that out. Although i had corrected before your post.
To display the number on page
<html>
<body>
<script language="javascript">
function make2digit(value) {
if (parseInt(value) < 10) { return ('0'+value); }
return (value);
}
function GenerateUnique() {
var dt = new Date();
var str = '';
str += (dt.getYear()-2000);
str += make2digit(dt.getMonth()+1 );
str += make2digit(dt.getDay());
str += make2digit(dt.getHours());
str += make2digit(dt.getMinutes() );
return str;
}
alert (GenerateUnique());
document.form1.unqfld.valu e = GenerateUnique();
document.getElementById('u nqdiv').in nerHTML = GenerateUnique();
</script>
</body>
<form name="form1">
<input type="text" name="unqfld" readonly value="">
</form>
<div id="unqdiv">UNIQUE NUMBER GOES HERE</div>
</html>
To display the number on page
<html>
<body>
<script language="javascript">
function make2digit(value) {
if (parseInt(value) < 10) { return ('0'+value); }
return (value);
}
function GenerateUnique() {
var dt = new Date();
var str = '';
str += (dt.getYear()-2000);
str += make2digit(dt.getMonth()+1
str += make2digit(dt.getDay());
str += make2digit(dt.getHours());
str += make2digit(dt.getMinutes()
return str;
}
alert (GenerateUnique());
document.form1.unqfld.valu
document.getElementById('u
</script>
</body>
<form name="form1">
<input type="text" name="unqfld" readonly value="">
</form>
<div id="unqdiv">UNIQUE NUMBER GOES HERE</div>
</html>
lvandevender,
you could have closed this one before other one.
Anyway, close this one now.
you could have closed this one before other one.
Anyway, close this one now.
How about this:
<html>
<head>
<title>Zvonko *</title>
<script>
function getUnique(theBtn){
var theForm = theBtn.form;
theForm.BPnr.value = (new Date()).getTime().toString ().substr( 3);
}
</script>
</head>
<body>
<form>
<input type="button" value="Generate" onClick="getUnique(this)">
<br>
<input type="text" name="BPnr" size="10" maxlength="10">
</form>
</body>
</html>
<html>
<head>
<title>Zvonko *</title>
<script>
function getUnique(theBtn){
var theForm = theBtn.form;
theForm.BPnr.value = (new Date()).getTime().toString
}
</script>
</head>
<body>
<form>
<input type="button" value="Generate" onClick="getUnique(this)">
<br>
<input type="text" name="BPnr" size="10" maxlength="10">
</form>
</body>
</html>
Or if the first digit should not be zero:
<html>
<head>
<title>Zvonko *</title>
<script>
function getUnique(theBtn){
var theForm = theBtn.form;
theForm.BPnr.value = "7"+(new Date()).getTime().toString ().substr( 4);
}
</script>
</head>
<body>
<form>
<input type="button" value="Generate" onClick="getUnique(this)">
<br>
<input type="text" name="BPnr" size="10" maxlength="10">
</form>
</body>
</html>
<html>
<head>
<title>Zvonko *</title>
<script>
function getUnique(theBtn){
var theForm = theBtn.form;
theForm.BPnr.value = "7"+(new Date()).getTime().toString
}
</script>
</head>
<body>
<form>
<input type="button" value="Generate" onClick="getUnique(this)">
<br>
<input type="text" name="BPnr" size="10" maxlength="10">
</form>
</body>
</html>
I saw
https://www.experts-exchange.com/questions/21891575/unique-number-generator2.html
Guys stop stealing code.
https://www.experts-exchange.com/questions/21891575/unique-number-generator2.html
Guys stop stealing code.
Stealing? Does my code version has to do ANYTHING with yours?
Or do you want this pointz ;-)
Or do you want this pointz ;-)
Guys,
This is not about the points.
Visit the pages,
https://www.experts-exchange.com/questions/21892486/number-generator-out-help.html
https://www.experts-exchange.com/questions/21891575/unique-number-generator2.html
Asker seeks help based on the my post for this.
I have not problem with that.
For some reason , asker wants to close the Question, and get points refunded
that is okay by me.
_PA
This is not about the points.
Visit the pages,
https://www.experts-exchange.com/questions/21892486/number-generator-out-help.html
https://www.experts-exchange.com/questions/21891575/unique-number-generator2.html
Asker seeks help based on the my post for this.
I have not problem with that.
For some reason , asker wants to close the Question, and get points refunded
that is okay by me.
_PA
And what from YOUR code you think is stolen by me?
<html>
<body>
<script language="javascript">
function make2digit(value) {
if (parseInt(value) < 10) { return ('0'+value); }
return (value);
}
function GenerateUnique() {
var dt = new Date();
var str = '';
str += (dt.getYear()-2000);
str += make2digit(dt.getMonth()+1
str += make2digit(dt.getDay());
str += make2digit(dt.getHours());
str += make2digit(dt.getMinutes()
return str;
}
alert (GenerateUnique());
</script>
</body>
</html>