Appframe Knowledge Base


1 hits
0

How to format dates and numbers

//----- Format as date -----

//Format dates using default format
af.common.format(new Date(),{type:'date'});
//Returns date formatted as dd-MMM-yyyy (i.e 10-apr-2013)

//Format dates using custom format
af.common.format(new Date(),{type:'date',format:'dd-MM-yy'});
//Returns date formatted as dd-MM-yy (i.e 10-04-13)

//Format date including time (UTC is used by default if not specified)
af.common.format(new Date(),{type:'date',format:'dd-MM-yy hh:mm'});
//Returns UTC date and time formatted as dd-MM-yy hh:mm (i.e 10-04-13 04:41)

//Format date including time and not using UTC format (UTC is used by default if not specified)
af.common.format(new Date(),{type:'date',format:'dd-MM-yy hh:mm',utc:false});
//Returns non-UTC date formatted as dd-MM-yy hh:mm (i.e 10-04-13 04:41)


//----- Format as filesize (specified in byte) note: only supports up to 1000 TB -----

af.common.format('1.2345',{type:'filesize',decimals:2});
//Returns 1.23 B

af.common.format('1024',{type:'filesize',decimals:2});
//Returns 1 KB (decimals will not be shown when 0 is returned for all decimals, so 1.00 but will be shown as 1)

af.common.format('1048576',{type:'filesize'});
//Returns 1 MB


//----- Format strings -----

// Can be used to format strings that for example have been translated
af.common.format("Record {0} of {1}", vIndex + 1, vTotal);
// Calling when vIndex = 0 and vTotal = 100 returns:
// "Record 1 of 100"

common web · Perma link post comment Posted by: Øystein Kaldestad (12-apr-2013)