|
#1
|
|||
|
|||
|
I want to only display the date and strip the time portion from Date.toNormalDate() if the time is 12:00:00 AM.
How can I do this? Is there custom date format templates or can I only use the function references as listed in DateDisplayFormat |
|
#2
|
|||
|
|||
|
Here's how I solved it:
Code:
var dt = Date.parseInput(value); var ret = dt.toNormalDate(); ret = ret.replace(/ 12:00:00 AM/,""); return ret; |
|
#3
|
|||
|
|||
|
Hi tgochenour,
Your approach will work fine. As you noted we also supply a set of standard other formats you can use with the toNormalDate() method. For a truly custom format such as the one you describe there are a couple of options: You can pass a custom formatter function directly into the toNormalDate() method. This function will be executed in the scope of the date object. Code:
var myDate = new Date();
function customFormatter () {
return this.getFullYear() + "." + (this.getMonth() +1) + "." +
this.getDate();
}
isc.warn(myDate.toNormalDate(customFormatter));
Or you can set your custom formatter function up as the standard normal formatter via Date.setNormalDisplayFormat(), like this: Code:
function customFormatter () {
return this.getFullYear() + "." + (this.getMonth() +1) + "." +
this.getDate();
}
Date.setNormalDisplayFormat(customFormatter);
var myDate = new Date();
isc.warn(myDate.toNormalDate(customFormatter));
However if you're not coping this in multiple places in your app, it's probably not necessary to rework your approach. |
|
#4
|
|||
|
|||
|
In your second example, did you mean to say:
Code:
Date.setNormalDisplayFormat(customFormatter); var myDate = new Date(); isc.warn(myDate.toNormalDate(customFormatter)); Code:
Date.setNormalDisplayFormat(customFormatter); var myDate = new Date(); isc.warn(myDate.toNormalDate()); |
|
#5
|
|||
|
|||
|
Sorry - you're right I meant to say
isc.warn(myDate.toNormalDate()); No need to pass the formatter function into the toNormalDate() method as a parameter since it's already been set up as the default. Thanks for catching that |