CultureInfo.dateToStr

Syntax

dateToStr(date: Date, noTime: Boolean, noDate: Boolean);

Parameters

date. Date to convert.

noTime. Indicates that no time information is added to the string to return.

noDate. Indicates that no date information is added to the string to return.

Description

The dateToStr method converts date to a string in accordance with the current culture.

Comments

This method returns a String-type value.

Example

To execute the example, add a link to PP.js scenario file to HTML page. Get date of the first and last day of the second month of 2012, define short names for week days, date order, time separator, postfixes for 12 hour time display mode, and set the 12 hour time display mode. Specify a new date and get its text view. Get the number of days in January 2013, shift of the current time zone in milliseconds, and number of week. Convert hour value to 12 hour and 24 hour formats:

// Determine regional settings
var cultureInfo = new PP.CultureInfo();
// get date of the first week day with the 2 number in 2012 and output its string value
var firstDate = cultureInfo.getFirstWeekDate(2, 2012);
console.log("Text view of the first week day date with the 2 number in 2012: " + firstDate.toString());
// Get date of the last week day with the 2 number in 2012 and output its string value
var lastDate = cultureInfo.getLastWeekDate(2, 2012);
console.log("Text view of the last week day date with the 2 number in 2012: " + firstDate.toString());
// Determine a new date
var date = new Date(2012, 1, 1);
// Determine short names for week days
cultureInfo.ShortDayNames = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
// Determine date separator
cultureInfo.DateSeparator = ".";
// Determine date forming order
cultureInfo.DateOrder = "ymd";
// Set 12-hour display mode
cultureInfo.Hour24Mode = False;
// Determine time separator
cultureInfo.TimeSeparator = "-";
// Determine postfixes for the 12-hour display mode
cultureInfo.TimeAmPm = ["PM", "AM"];
// Get text view of date
console.log("text view of date: " + cultureInfo.dateToStr(date, False, False));
// Get the number of days in January 2013 
console.log("Number of days in January 2013: " + cultureInfo.getDaysInMonth(1, 2013));
// Get current time zone offset in milliseconds
console.log("Current time zone offset in milliseconds: " + cultureInfo.getTimezoneOffsetInMsec());
// Get week number in the year
console.log("Week number in the year: " + cultureInfo.getWeekNumber(date));
// Transform hours to 12-hour format
var res = cultureInfo.to12hMode(18);
var postfix = res[1] ? cultureInfo.TimeAmPm[1] : cultureInfo.TimeAmPm[0];
console.log("12-hour view: " + res[0] + " " + postfix);
//Transform hours to 24-hour format
var res2 = cultureInfo.to24hMode(6, False);
console.log("24-hour view: " + res2);

After executing the example the browser console displays dates of the first and last days in the second month of 2012, text view of the received date, number of days in January 2013, offset of the current time zone (in milliseconds), number of the week that contains this date, 12 hour and 24 hour time format:

Text view for the date of the first day in the week 2 in 2012: Sun Jan 15 2012 00:00:00 GMT+0400 (Moscow time zone (winter))

Text view for the date of the last day in the week 2 in 2012: Sun Jan 15 2012 00:00:00 GMT+0400 (Moscow time zone (winter))

Text view of the date: 2012.02.01 12-00-00 p.m.

Number of days in January 2013: 28

Offset of the current time zone in milliseconds: -14400000

Number of week in the year: 4

12 hour time format: 6 P.M.

24 hour time format: 18

See also:

CultureInfo