Utility functions
Utils
A collection of general purpose utility functions which can be used independently from Mobiscroll component instances.
Platform
import { platform } from '@mobiscroll/angular';
Description
Information about the current platform.
name
String
Possible values:
iosandroidwindows
majorVersion
Number
The major version of the platform
minorVersion
Number
The minor version of the platform
Format date
import { formatDate } from '@mobiscroll/angular';
Description
Format a date into a string value with a specified format.
Example
formatDate('yy-mm-dd', new Date(2015, 1, 19)); // Produces '2015-02-19'
Parameters
format
String
The format can be combinations of the following:
M- month of year (no leading zero)MM- month of year (two digit)MMM- month name shortMMMM- month name longD- day of month (no leading zero)DD- day of month (two digit)DDD- day of week (short)DDDD- day of week (long)YY- year (two digit)YYYY- year (four digit)h- 12 hour format (no leading zero)hh- 12 hour format (leading zero)H- 24 hour format (no leading zero)HH- 24 hour format (leading zero)m- minutes (no leading zero)mm- minutes (leading zero)s- seconds (no leading zero)ss- seconds (leading zero)a- lowercase am/pmA- uppercase AM/PM'...'- literal text''- single quote- anything else - literal text
date
Date
The date value to format
settings
Object
A set of key/value pairs that configure the format. All settings are optional:
- amText (default:
'am') - Text for AM - dayNames (default:
['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']) - The list of long day names, starting from Sunday. - dayNamesShort (default:
['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']) - The list of abbreviated day names, starting from Sunday. - monthNames (default:
['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']) - The list of full month names. - monthNamesShort (default:
['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']) - The list of abbreviated month names. - pmText (default:
'pm') - Text for PM - shortYearCutoff (default:
'+10') - Set the cutoff year for determining the century for a date (used in conjunction with dateFormat 'y'). If a numeric value (0-99) is provided then this value is used directly. If a string value is provided then it is converted to a number and added to the current year. Once the cutoff year is calculated, any dates entered with a year value less than or equal to it are considered to be in the current century, while those greater than it are deemed to be in the previous century.
Parse date
import { parseDate } from '@mobiscroll/angular';
Description
Extract a date from a string value with a specified format.
Example
parseDate('yy-mm-dd', '2015-02-19')); // returns date object
Parameters
format
String
The format can be combinations of the following:
M- month of year (no leading zero)MM- month of year (two digit)MMM- month name shortMMMM- month name longD- day of month (no leading zero)DD- day of month (two digit)DDD- day of week (short)DDDD- day of week (long)YY- year (two digit)YYYY- year (four digit)h- 12 hour format (no leading zero)hh- 12 hour format (leading zero)H- 24 hour format (no leading zero)HH- 24 hour format (leading zero)m- minutes (no leading zero)mm- minutes (leading zero)s- seconds (no leading zero)ss- seconds (leading zero)a- lowercase am/pmA- uppercase AM/PM'...'- literal text''- single quote- anything else - literal text
value
String
The string value to parse
settings
Object
A set of key/value pairs that configure the format. All settings are optional:
- amText (default:
'am') - Text for AM - dayNames (default:
['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']) - The list of long day names, starting from Sunday. - dayNamesShort (default:
['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']) - The list of abbreviated day names, starting from Sunday. - monthNames (default:
['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']) - The list of full month names. - monthNamesShort (default:
['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']) - The list of abbreviated month names. - pmText (default:
'pm') - Text for PM - shortYearCutoff (default:
'+10') - Set the cutoff year for determining the century for a date (used in conjunction with dateFormat 'y'). If a numeric value (0-99) is provided then this value is used directly. If a string value is provided then it is converted to a number and added to the current year. Once the cutoff year is calculated, any dates entered with a year value less than or equal to it are considered to be in the current century, while those greater than it are deemed to be in the previous century.