Forum guidelines
  • Home
  • »
  • Tablet PC
  • »
  • How to Write a Only Time Format HH:MM:SS in TextBox
AuthorQuestion
How to Write a Only Time Format HH:MM:SS in TextBox
Posted on: 16 Jun 2008

Hi All,

How to display the Time format in Textbox like this HH:MM:SS

Pls How to do..pls any examples

Regards

Somasundaram G


Somasundaram G
AuthorReply
Re: How to Write a Only Time Format HH:MM:SS in TextBox
Posted on: 16 Jun 2008  

<PUBLIC:COMPONENT URN="hide">
    <PUBLIC:ATTACH EVENT="onfocus" ONEVENT="OnFocus()" />
    <PUBLIC:ATTACH EVENT="onblur" ONEVENT="OnBlur()" />
    <PUBLIC:ATTACH EVENT="onkeyup" ONEVENT="OnKeyUp()" />
    <PUBLIC:ATTACH EVENT="ondblclick" ONEVENT="OnDblClick()" />
    <PUBLIC:ATTACH EVENT="onkeydown" ONEVENT="OnKeyDown()" />
    <PUBLIC:ATTACH EVENT="onkeypress" ONEVENT="OnKeyPress()" />
    <PUBLIC:ATTACH EVENT="onclick" ONEVENT="OnClick()" />
    
    <script LANGUAGE="jscript">
    var ValidationFired;
    ValidationFired = false;
    var splitarr="/";

    function OnKeyDown()
    {
            if (event.keyCode==13) event.keyCode=9;
    }
    
    function OnClick()
    {
        this.select();
    
    }

    function OnFocus()
    {
        //this.style.background='#99ccff';
     }

    function OnBlur()
    {
        if (this.value.length>6)
        {
            tmpArr = this.value.split(splitarr);
            
            if (tmpArr.length==3)
            {
                if(tmpArr[2].length==3)
                {
                    dispAlert("Please Enter Valid Year");
                    return;
                }
        
                if(tmpArr[2].length==2)
                //Transform a 2 digit yeat into a 4 digit year.
                var year = parseInt(tmpArr[2]);
                if(year < 50)
                {
                    this.value = this.value.substring(0,this.value.length-2) + "20"+tmpArr[2];
                }
                else
                {   
                    if(year < 100)
                    {
                        this.value = this.value.substring(0,this.value.length-2) + "19"+tmpArr[2];
                    }
                }
            }    
            
        // ValidationFired = true;
        }
    
        if(!this.value.length)
        {
            //this.style.background = '#FFEBE6';
            return;
        }
    
        if(!ValidationFired)
        {
        //alert (this.value.length);
            if(this.value.length < 10 || this.value.length >10 )
            {
                var retval=checkvaliddate(this);
                if (retval==false)
                {
                    dispAlert("Please Enter Valid Date");
                    this.focus();
                    return;
                }    
            }
            else if (this.value.length == 10)
            {
                dtValue = this.value.split(splitarr);
                lDate =  parseInt(dtValue[0],10);
                lMonth = parseInt(dtValue[1],10);
                lYear =  parseInt(dtValue[2],10);
                if (!isDateJ(lMonth,lDate,lYear))
                {
                    dispAlert("Please Enter Valid Date");
                    this.focus();
                    return;
                }
            }
        }
        //    this.style.background = '#FFEBE6';
    }

    function OnDblClick()
    {
        /*
        marray=new Array();
        marray[0]=this;
        marray[1]="";
        showModalDialog("fncal.htm",marray,"border=thin;center=yes;dialogTop= 120px; dialogleft= 130px; dialogWidth=180px; dialogHeight=248px;help=0;status=no;maximize=no;minimize=no;status=no;scroll=no;");
        */    
    }

    function OnKeyPress()
    {
        window.event.keyCode=CheckKey(window.event.keyCode);    
        if(this.value.length==10){this.value = '';}    
    }

    function OnKeyUp()
    {
     Validatetime();
    }

    function CheckKey(keycode)
    {
         return ((keycode > 47 && keycode < 58) ? keycode : 0);
    }

    function Validatetime()
    {
        if(window.event.keyCode == 8 || window.event.keyCode == 36 || window.event.keyCode == 37 || window.event.keyCode == 46)    
        {
            this.value = "";
            return;
        }
    
        if(this.value.length==2)
        {
            if(this.value==0 || this.value>31)
            {
                dispAlert("Please Enter Valid Date");
                return;
            }
            else this.value += splitarr;
        }
        
        if(this.value.length==5)
        {
            var arr=this.value.split(splitarr);
            if(arr[1]==0 || arr[1]>12)
            {
                dispAlert("Please Enter Valid Month");
                return;
            }
            else this.value += splitarr;
        }
        
        
        ValidationFired=false;
    }

    function dispAlert(lMsg) {
    ValidationFired=true;
    alert(lMsg);
    this.value = "";
    }

    function isLeapYear(lYear) {
    if(((lYear%4 == 0) && (lYear%100 !=0)) || (lYear%400 ==0))
        return true;
    else
        return false;
    }

    function isDateJ(lMonth,lDate,lYear) {
        
    switch(lMonth) {
        case 4:
        case 6:
        case 9:
        case 11:
            if(lDate > 30)     return false;
        break;
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            if(lDate > 31) return false;
        break;    
        case 2:
            if(isLeapYear(lYear)) {
                if(lDate>29) return false;
            }
            else
                if(lDate>28) return false;
        break;        
    }
    return true;
    }
    
    
    
    
    
    
    
</script>

<script LANGUAGE="vbscript">
    function checkvaliddate(obj)
        checkvaliddate=isdate(obj.value)
    end function
</script>

</PUBLIC:COMPONENT>

 

 

or else on server side u can use

 this.CustomFormat = " HH:mm:ss";

 

atleast this vl help u out


prathima
Re: How to Write a Only Time Format HH:MM:SS using DateTimePicker Visual C#.Net
Posted on: 16 Jun 2008  

Hi

thankyou very much for Response....Can i use DateTimePicker??? If i use DateTimePicker..Only I want Time Format  Like this (HH:MM:SS)..this is Easy way using C#  Windows Application....So please tell me How to do??? 


Somasundaram G
Re: How to Write a Only Time Format HH:MM:SS in TextBox
Posted on: 16 Jun 2008  

say your textbox id is txtTime.
You can use the folowing code to display the time:

txtTime.Text = DateTime.Now.ToString("HH:mm ss tt");


Regards,
Niradhip(James Hetfield)
MCP,MVC,MVP(Mindcracker)
--------------------------------------------------------------------------------------
Please remember to click “Do you like this answer” on the post that helps you.

SPONSORED BY

Offshore Software and Database Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.