问题
I searched a bit but couldn't find the answer.
I want to get current date and format to YYYYMMDD
I cannot use EXSLT as per my requirements.
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/5309370/how-to-format-date-in-xslt-1-0