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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    getMonth what am I doing wrong

    I'm new to java and have been given the following piece of code to try and fix.

    The code is renaming an existing HTML file with the current date but the problem is the date is out by one. I'm aware that in java Jan=0 Feb=1 etc but just dont know enough to know how to fix this...

    If I add +1 to getmonth all that happens is the file gets named LEICESTER_DAILY - 24-71-2011 17.20.36 rather than LEICESTER_DAILY - 24-8-2011 17.20.36

    Here's the piece of code

    Code:
    function makePerm() {
    var txtFile;
    	// Swap the temporary file with the original
    	if (fileSys.FileExists(grabParentFolderUrl() + 'tempsave.htm')) {
    		txtFile = fileSys.getFile(grabParentFolderUrl() + 'tempsave.htm');
    		if (!(txtFile.size == 0)) { // Check file is not empty
    			if (fileSys.FileExists(grabParentFolderUrl() + 'LEICESTER_DAILY.htm')) { 
    				var today = new Date();
    				var timeStamp = today.getDate() + '-' + today.getMonth() + '-' + today.getFullYear() + ' ' + today.getHours() + '.' + today.getMinutes() + '.' + today.getSeconds();
    				txtFile = fileSys.getFile(grabParentFolderUrl() + 'LEICESTER_DAILY.htm');
    				txtFile.Move(grabParentFolderUrl() + 'LEICESTER_DAILY - ' + timeStamp.toString() + '.htm');
    				txtFile = fileSys.getFile(grabParentFolderUrl() + 'tempsave.htm');
    				txtFile.Move(grabParentFolderUrl() + 'LEICESTER_DAILY.htm');

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    There is a difference between
    Code:
    var timeStamp = today.getDate() + '-' + today.getMonth()+1 + '-' + today.getFullYear() + ' ' + today.getHours() + '.' + today.getMinutes() + '.' + today.getSeconds();
    and
    Code:
    var timeStamp = today.getDate() + '-' + (today.getMonth()+1) + '-' + today.getFullYear() + ' ' + today.getHours() + '.' + today.getMinutes() + '.' + today.getSeconds();
    The first one with evaluate getMonth() first, then convert it to a string, then convert 1 to a string and append it to the result of getMonth()

    The second one will evaluate getMonth() first and add 1 to it before(!) converting the result to a string. So this is what you'll need.

  • Users who have thanked devnull69 for this post:

    wibblemonster (08-24-2011)


  •  

    Posting Permissions

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