...

View Full Version : date and time



padasalgi
12-24-2011, 02:09 PM
I have created a kdate.js file in Kannada to display current, day,month,date,year and time.While the day,month are displayed in kannada the date,year time are shown in english.I want them to display in Kannada.Will some one guide me how I can do this and what are changes that to make in the javascript code.I have used unicode while writing Kannada script.
I also want to know how to increase and change font color and the time element to be displayed on the next line.
Please help and guide me.
thanks
js file in the form the text is sent as an attachment.

xelawho
12-24-2011, 07:45 PM
I don't know anything about Kannada but I guess it uses different numbers, or is it that it uses the same numbers but the year is different?

either way, I'm guessing that you will have to make a year array and populate it with what you want to display, the way you have with the days and months, rather than relying on the year object that javscript natively uses.

padasalgi
12-25-2011, 01:20 AM
I don't know anything about Kannada but I guess it uses different numbers, or is it that it uses the same numbers but the year is different?

either way, I'm guessing that you will have to make a year array and populate it with what you want to display, the way you have with the days and months, rather than relying on the year object that javscript natively uses.

Thanks.Kannada uses its own numbers .My problem is how to display only the time separately may be on the next line or on the right top.
As suggested I shall try an array in kannada but as I am new and do not know if it will have conflict of interest with default numbers.
pl advise.

xelawho
12-25-2011, 05:43 AM
maybe you can use something like this?



<html>
<head>
</head>
<body>

<div id="results"></div>
<script type="text/javascript">
var mydate =new Date;
var year=mydate.getFullYear()

switch (year){
case 2011:
myyear="fish";
break;
case 2012:
myyear="frog";
break;
case 2013:
myyear="bear"
break;
}
document.getElementById("results").innerHTML=myyear;
</script>

</body>
</html>

padasalgi
12-28-2011, 01:11 AM
maybe you can use something like this?



<html>
<head>
</head>
<body>

<div id="results"></div>
<script type="text/javascript">
var mydate =new Date;
var year=mydate.getFullYear()

switch (year){
case 2011:
myyear="fish";
break;
case 2012:
myyear="frog";
break;
case 2013:
myyear="bear"
break;
}
document.getElementById("results").innerHTML=myyear;
</script>

</body>
</html>


Thanks a lot. It is displaying year in Kannada.Can I use this code to display dates in Kannada insted of creating an array
please advise.

xelawho
12-28-2011, 01:25 AM
you could, but it would be a far less efficient way to do it. The switch only makes sense because the first year that you want to take into account is 2011 (so in an ordinary array you will have 2010 "empty" spaces), and the year will never repeat.

With months and days you have to provide for the possibility for 0 and you have to keep looping through, both of which are pretty much what an array is made for.

Why do you not want to use an array? It's simple to combine the two methods (although I had to swap back in the English days and months because, like I say my Kannada is a little rusty) :D



<html>
<head>
<style>
.datetime{
font-size:20px;
color:red;
font-family:arial;
}
</style>
</head>
<body onload="getTheDate()">
<div id="time" class="datetime"></div>
<div id="date" class="datetime"></div>
<script type="text/javascript">
var dayarray=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]
var montharray=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]

function getTheDate(){
var mydate = new Date();
var time=mydate.toLocaleTimeString().substr(0,13).toUpperCase();
var year=mydate.getFullYear()
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()

if (daym<10){daym="0"+daym}

switch (year){
case 2011:
var myyear="fish";
break;
case 2012:
var myyear="frog";
break;
case 2013:
var myyear="bear"
break;
}
document.getElementById("date").innerHTML=dayarray[day]+", "+montharray[month]+" "+daym+", "+myyear;
document.getElementById("time").innerHTML=time;
}
setInterval(getTheDate,1000);

</script>

</body>
</html>

padasalgi
12-31-2011, 08:53 PM
you could, but it would be a far less efficient way to do it. The switch only makes sense because the first year that you want to take into account is 2011 (so in an ordinary array you will have 2010 "empty" spaces), and the year will never repeat.

With months and days you have to provide for the possibility for 0 and you have to keep looping through, both of which are pretty much what an array is made for.

Why do you not want to use an array? It's simple to combine the two methods (although I had to swap back in the English days and months because, like I say my Kannada is a little rusty) :D



<html>
<head>
<style>
.datetime{
font-size:20px;
color:red;
font-family:arial;
}
</style>
</head>
<body onload="getTheDate()">
<div id="time" class="datetime"></div>
<div id="date" class="datetime"></div>
<script type="text/javascript">
var dayarray=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]
var montharray=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]

function getTheDate(){
var mydate = new Date();
var time=mydate.toLocaleTimeString().substr(0,13).toUpperCase();
var year=mydate.getFullYear()
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()

if (daym<10){daym="0"+daym}

switch (year){
case 2011:
var myyear="fish";
break;
case 2012:
var myyear="frog";
break;
case 2013:
var myyear="bear"
break;
}
document.getElementById("date").innerHTML=dayarray[day]+", "+montharray[month]+" "+daym+", "+myyear;
document.getElementById("time").innerHTML=time;
}
setInterval(getTheDate,1000);

</script>

</body>
</html>


Sir,
I did my best with my limited knowledge of javascript.I am unable to make an array in Kannada for dates and time.I do not know how to change these default values.Whatever I did it did not work.could you please send me the format of the code as you did for the year for time and date so that I can do the rest at this end.KANNADA is the Official language of Karnataka is spokena nd used by 6 crores of people in South India.Hence I am interested in using this in kannada format in my kannada webpages.I shall be obliged please help me.
"WISH YOU HAPPY NEW YEAR".
thanks

xelawho
12-31-2011, 10:07 PM
and who am I to argue with 60 million people?

there's probably a fancier way of doing this, but maybe you can use this, all you have to do is replace the letters "A", "B", "C" etc in this line:

return str.replace(/0/g,"A").replace(/1/g,"B").replace(/2/g,"C").replace(/3/g,"D").replace(/4/g,"E").replace(/5/g,"F").replace(/6/g,"G").replace(/7/g,"H").replace(/8/g,"I").replace(/9/g,"J");

with the characters that you want to use:


<html>
<head>
<style>
.datetime{
font-size:20px;
color:red;
font-family:arial;
}
</style>
</head>
<body onload="getTheDate()">
<div id="time" class="datetime"></div>
<div id="date" class="datetime"></div>
<script type="text/javascript">
var dayarray=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]
var montharray=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]

//var newstr

function rePlace(str){
return str.replace(/0/g,"A").replace(/1/g,"B").replace(/2/g,"C").replace(/3/g,"D").replace(/4/g,"E").replace(/5/g,"F").replace(/6/g,"G").replace(/7/g,"H").replace(/8/g,"I").replace(/9/g,"J");
}

function getTheDate(){
var mydate = new Date();
time=rePlace(mydate.toLocaleTimeString().substr(0,13).toUpperCase())
var year=mydate.getFullYear()
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=rePlace(mydate.getDate().toString())



switch (year){
case 2011:
var myyear="fish";
break;
case 2012:
var myyear="frog";
break;
case 2013:
var myyear="bear"
break;
}
document.getElementById("date").innerHTML=dayarray[day]+", "+montharray[month]+" "+daym+", "+myyear;
document.getElementById("time").innerHTML=time;
}
setInterval(getTheDate,1000);

</script>

</body>
</html>

xelawho
01-01-2012, 12:01 AM
slightly fancier (just replace the letters in the nums array with the characters you want to display):



<html>
<head>
<style>
.datetime{
font-size:20px;
color:red;
font-family:arial;
}
</style>
</head>
<body onload="getTheDate()">
<div id="time" class="datetime"></div>
<div id="date" class="datetime"></div>
<script type="text/javascript">
var dayarray=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
var montharray=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]

var nums=["A","B","C","D","E","F","G","H","I","J"];

function rePlace(str){
for (x in str){
for (var e=0; e<10; e++) {
if (str[x]==e){
str=str.replace(str[x],nums[e])
}
}
}
return str;
}

function getTheDate(){
var mydate = new Date();
time=rePlace(mydate.toLocaleTimeString().substr(0,8))
pm=mydate.toLocaleTimeString().substr(9,13).toUpperCase()
var year=mydate.getFullYear()
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=rePlace(mydate.getDate().toString())



switch (year){
case 2011:
var myyear="fish";
break;
case 2012:
var myyear="frog";
break;
case 2013:
var myyear="bear"
break;
}
document.getElementById("date").innerHTML=dayarray[day]+", "+montharray[month]+" "+daym+", "+myyear;
document.getElementById("time").innerHTML=time+" "+pm;
}
setInterval(getTheDate,1000);

</script>

</body>
</html>


I don't know which is better... probably neither - I suspect that there is a much better approach out there... somewhere... :rolleyes:

xelawho
01-01-2012, 04:08 PM
so, I think(!) this is my last swing at it... You'll be happy to note that I took the switch out, meaning that the year translates itself the same as the other numbers, making the code self-maintaining (at least until the internet breaks).

ಹ್ಯಾಪಿ ನ್ಯೂ ಇಯರ್ (I hope I got that right :D)



<html>
<head>
<style>
.datetime{
font-size:20px;
color:red;
font-family:arial;
}
</style>
</head>
<body onload="getTheDate()">
<div id="time" class="datetime"></div>
<div id="date" class="datetime"></div>
<script type="text/javascript">
var dayarray=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
var montharray=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
var nums=["A","B","C","D","E","F","G","H","I","J"];

function rePlace(str){
for (x in str) {
num=str[x]
if(num.match(/\d/)){
str=str.replace(num, nums[num]);
}
}
return str;
}

function getTheDate(){
var mydate = new Date();
time=rePlace(mydate.toLocaleTimeString().substr(0,13).toUpperCase())
var year=rePlace(mydate.getFullYear().toString())
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=rePlace(mydate.toString().substr(8,2))
document.getElementById("date").innerHTML=dayarray[day]+", "+montharray[month]+" "+daym+", "+year;
document.getElementById("time").innerHTML=time;
}
setInterval(getTheDate,1000);

</script>

</body>
</html>

padasalgi
01-06-2012, 05:42 PM
so, I think(!) this is my last swing at it... You'll be happy to note that I took the switch out, meaning that the year translates itself the same as the other numbers, making the code self-maintaining (at least until the internet breaks).

ಹ್ಯಾಪಿ ನ್ಯೂ ಇಯರ್ (I hope I got that right :D)



<html>
<head>
<style>
.datetime{
font-size:20px;
color:red;
font-family:arial;
}
</style>
</head>
<body onload="getTheDate()">
<div id="time" class="datetime"></div>
<div id="date" class="datetime"></div>
<script type="text/javascript">
var dayarray=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
var montharray=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
var nums=["A","B","C","D","E","F","G","H","I","J"];

function rePlace(str){
for (x in str) {
num=str[x]
if(num.match(/\d/)){
str=str.replace(num, nums[num]);
}
}
return str;
}

function getTheDate(){
var mydate = new Date();
time=rePlace(mydate.toLocaleTimeString().substr(0,13).toUpperCase())
var year=rePlace(mydate.getFullYear().toString())
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=rePlace(mydate.toString().substr(8,2))
document.getElementById("date").innerHTML=dayarray[day]+", "+montharray[month]+" "+daym+", "+year;
document.getElementById("time").innerHTML=time;
}
setInterval(getTheDate,1000);

</script>

</body>
</html>


Thanks a lot. I shall try and follow ur instructions and guidance shall revert to you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum