sprintf() functionality 
Author Message
 sprintf() functionality

After working with the string-making functions of the Date object, it seems
I have found a sore need for implementing something like an sprintf
function.  For example, how does one get a leading zero in the
hours/minutes/seconds?

If it's a waste of time to add such a function to my JS library (I've
already started), please let me know of the built-in alternatives.

thanx



Sun, 20 Jul 2003 23:12:54 GMT  
 sprintf() functionality
Here is a function I wrote to accomplish this for the day and month and also
show the four digit year.

I believe it could be modified to accomplish this.

function DateDemo(datevar, theobj)
{
   var d, s;
   d = new Date(datevar);
   if ((d.getMonth() + 1) < 10)
   {
     s = '0' + (d.getMonth() + 1) + "/";
   }
   else
   {
     s = (d.getMonth() + 1) + "/";
   }
   if (d.getDate() < 10)
   {
     s += '0' + d.getDate() + "/";
   }
   else
   {
     s += d.getDate() + "/";
   }
   if (d.getYear() < 100)
   {
     if (d.getYear() < 50)
     {
       s += (2000 + d.getYear());
     }
     else
     {
       s += (1900 + d.getYear());
     }
   }
   else
   {
   s += d.getYear();
   }
   theobj.value = s;

Quote:
}

hth

Anthony Sullivan MCP, GMT, GST
Analyst/Programmer
Ajilon Services, Inc

Check out the ASP FAQ! http://www.aspfaq.com
"From the mouths of babes comes ... slobber."

Quote:

>After working with the string-making functions of the Date object, it seems
>I have found a sore need for implementing something like an sprintf
>function.  For example, how does one get a leading zero in the
>hours/minutes/seconds?

>If it's a waste of time to add such a function to my JS library (I've
>already started), please let me know of the built-in alternatives.

>thanx



Mon, 21 Jul 2003 02:53:43 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. printf (or sprintf) equivalent in jscript?

2. printf / sprintf equivalent?

3. Context Menu Functionality and VBScript

4. need clipboard functionality within vbscript

5. GS3.51 - Windows NT Functionality question

6. Select box functionality needed

7. have you ever tried drag-and-drop functionality in your Web page

8. JavaScript/radio buttons functionality issues...

9. wait or sleep functionality

10. IE functionality change in image load

11. Window object functionality for Netscape

12. jscript to produce a tooltip like functionality

 

 
Powered by phpBB® Forum Software