www.webdeveloper.com
Results 1 to 2 of 2

Thread: date format change - function call inside an object

Hybrid View

  1. #1
    Join Date
    Aug 2012
    Posts
    3

    date format change - function call inside an object

    Here is my code..
    Code:
    $('<div />').addblock(
    {
    	type:'common', 
    	title:'Text Block', 
    	data:{	'id':model.id,
    			"namne":model.name,
    			"desc":model.desc,
    			"labelDate":model.thetimestamp
    			/*
    			"labelDate": function(models.starttime){
    				var value = models.starttime;
    				var d = new Date();
    				d.setTime(value);
    				value = d.toLocaleDateString();	
    				return value;
    			}
    			*/
    	}
    			
    });
    I'm getting model.thetimestamp from an ajax call, however I am not able to format that to date object. Im trying to do that using an anonymous function which is now in the comments. How do I format the date before showing it in the block?

  2. #2
    Join Date
    Nov 2006
    Location
    Oakland
    Posts
    500
    It depends on what models.startime is. The JavaScript Date() constructor can takes various type of arguments: milliseconds, date string or Year, Month, Day, Hours, Minutes, Seconds, milliseconds

    You could write:

    "labelDate": function(models.starttime){
    var d=new Date(parseInt(arguments[0]));
    return d.toLocaleDateString();
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles