Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11

Thread: date and time

  1. #1
    New Coder
    Join Date
    Mar 2003
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    date and time

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

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,968
    Thanks
    56
    Thanked 557 Times in 554 Posts
    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.

  • #3
    New Coder
    Join Date
    Mar 2003
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by xelawho View Post
    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.

  • #4
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,968
    Thanks
    56
    Thanked 557 Times in 554 Posts
    maybe you can use something like this?

    Code:
    <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>

  • #5
    New Coder
    Join Date
    Mar 2003
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by xelawho View Post
    maybe you can use something like this?

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

  • #6
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,968
    Thanks
    56
    Thanked 557 Times in 554 Posts
    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)

    Code:
    <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>
    Last edited by xelawho; 12-28-2011 at 04:20 AM.

  • #7
    New Coder
    Join Date
    Mar 2003
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by xelawho View Post
    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)

    Code:
    <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

  • #8
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,968
    Thanks
    56
    Thanked 557 Times in 554 Posts
    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:
    Code:
    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:

    Code:
    <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>

  • #9
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,968
    Thanks
    56
    Thanked 557 Times in 554 Posts
    slightly fancier (just replace the letters in the nums array with the characters you want to display):

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

  • #10
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,968
    Thanks
    56
    Thanked 557 Times in 554 Posts
    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 )

    Code:
    <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>
    Last edited by xelawho; 01-01-2012 at 04:55 PM. Reason: one more bite at the apple

  • #11
    New Coder
    Join Date
    Mar 2003
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by xelawho View Post
    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 )

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


  •  

    LinkBacks (?)


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •