How to format DATE in XSLT 1.0
I searched a bit but co开发者_StackOverflow社区uldn't find the answer.
I want to get current date and format to YYYYMMDD
I cannot use EXSLT as per my requirements.
A very simple Inline C# Script Functoid could look like this:
public string MyDateFormat(string dateValue)
{
string result = String.Empty;
string outputFormat = "{0:yyyyMMdd}";
DateTime parsed;
if (DateTime.TryParse(dateValue, out parsed))
{
result = String.Format(outputFormat, parsed);
}
else
{
result = String.Format(outputFormat, DateTime.MinValue);
}
return result;
}
For a similar problem I created a External Assembly which will allow to specify CultureInfo
for parsing the input DateTime string and also submit the output format string as a functoid input parameter.
You want the substring to act on the date.
To get the date:
substring-before($dateTime, 'T')
To get the year you want to work on the above result:
substring-before($previousResult, '-')
Then concatenate the values you got from the string manipulations.
This explains the whole thing and wraps it on a template: Format a date in XML via XSLT
etc
Hope this helps.
精彩评论