Adding Current Time To a Filename 
Author Message
 Adding Current Time To a Filename

I want to add the current time in h,m,s to a filename e.g.

test.txt becomes 135807test.txt

anybody any suggestions

thanks

alan



Sat, 03 May 2003 03:00:00 GMT  
 Adding Current Time To a Filename

  var now = new Date();
  var hours = now.getHours();
  hours = hours < 10 ? '0' + hours : hours;
  var minutes = now.getMinutes();
  minutes = minutes < 10 ? '0' + minutes : minutes;
  var seconds = now.getSeconds();
  seconds = seconds < 10 ? '0' + seconds : seconds;
  var fileName = 'test.txt';
  fileName = hours + minutes + seconds + fileName;

Quote:

> I want to add the current time in h,m,s to a filename e.g.

> test.txt becomes 135807test.txt

> anybody any suggestions

> thanks

> alan

--

        Martin Honnen
        http://javascript.faqts.com/
        http://home.t-online.de/home/martin.honnen/jsgoddies.html



Sat, 03 May 2003 03:00:00 GMT  
 Adding Current Time To a Filename

Hi

var d = new Date();
fileName =  ( padIt( d.getHours() ) + padIt( d.getMinutes() ) +
adIt( d.getSeconds() )  +   fileName );

And perhaps ..

function padIt( v ){
return ( v < 10 ) ? ( "0" + v ) : v;

Quote:
}

--
--
Best Regards
  Vidar Petursson
 ==============================
   Microsoft Internet, Client, SDK MVP
 ==============================
 http://www.icysoft.com
 http://www.dna.is



 ==============================
  No matter where you go there you are
 ==============================
--


Quote:
> I want to add the current time in h,m,s to a filename e.g.

> test.txt becomes 135807test.txt

> anybody any suggestions

> thanks

> alan



Sat, 03 May 2003 03:00:00 GMT  
 Adding Current Time To a Filename

Use the getHours, getMinutes and getSeconds methods of the Date object.

=-=-=
Steve
-=-=-


Quote:
> I want to add the current time in h,m,s to a filename e.g.

> test.txt becomes 135807test.txt

> anybody any suggestions

> thanks

> alan



Sat, 03 May 2003 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. new filename as current time : basic question

2. Adding time to current date

3. Displaying the Current Date and Current Time

4. Formatting Time to GMT when current Time Zone not known

5. How can one read the current filename?

6. How to automatically write the current date in a filename

7. Adding filename to separator pages?

8. add date to filename

9. Upload and add the filename to a database

10. Extract zip file with current time

11. Lookng for a function to XOR ip address and current time

12. Get Current Time

 

 
Powered by phpBB® Forum Software