I'm looking to output a timestamp of when content was published within Umbraco, in the correct format required by the HTML5 <time> element.
For example:
<time datetime="2012-02-28T20:00+00:00" pubdate>February 28, 2012</time>
Is there a way to achieve this within Umbraco or with Razor? I know with PHP there's a particular "W3C" way of outputting timestamps: http://goo.gl/sEFsh.
More info on correct formatting of this element can be found here: http://html5doctor.com/the-time-element/
How about this in razor:
#DateTime.Now.ToString("yyyy-MM-ddTHH:mmzzz")
This does not generate any output for seconds and milliseconds as in your example.
I think the format string you may be looking for is "o", like this (in razor):
#{
var now = DateTime.Now;
}
<time datetime="#now.ToString("o")" pubdate>#now.ToLongDateString()</time>
Produces this for me:
<time datetime="2012-02-28T11:41:50.3697628-05:00" pubdate>Tuesday, February 28, 2012</time>
It looks like the best option for this might be to use the global "UpdateDate" like this:
<time datetime="#Model.UpdateDate.ToString("yyyy-MM-ddTH:mmzzz")" pubdate>
#Model.UpdateDate.ToLongDateString()
</time>
Seems to output the desired format and the date published rather than the current date. Can anyone see any issues with this solution?
Use .ToString("s")
<time datetime="#Model.UpdateDate.ToString("s")">...</time>
The output will generate: "2013-02-15T21:15:07" and pass html validation
http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx
I usually just use this code in cshtml
#yourDate.Date.ToString("yyyy-MM-dd")T00:00+00:00
Related
t-field-option is not working.
I have tried
<span t-field="o.date_invoice" t-field-options='{"format": "MM/dd/yyyy"}'/>
Instead of using
<span t-field="o.date_invoice" t-field-options='{"format": "MM/dd/yyyy"}'/>
use
<span t-field="o.date_invoice" t-options='{"format": "MM/dd/yyyy"}'/>
Hope that helps!
For those who arrive here from search engines, you can control display of date in form fields using widgets.
<field name="date_planned" widget="date"/>
or,
<field name="date_planned" widget="datetime"/>
In v12, the date/datetime fields are python date/datetime objects and not string representations. The following python formatting will work in v12 reports:
<span t-esc="o.date_invoice.strftime('%m/%d/%Y')"/>
https://www.odoo.com/groups/technical-62/technical-56392463
To display localized date strings. Try the following:
<span t-field="o.date_invoice" t-options="{"widget": "date"}" />
To delete the time section:
<span t-field="o.date_invoice" t-field-options='{"widget": "date"}'/>
Use t-field-options instead of t-options
Do not change the position of the quotes in t-field-options
This code respects the format date according to lang/country.
Try this.
<span t-esc="datetime.datetime.strptime(o.sale_id.confirmation_date, '%Y-%m-%d %H:%M:%S').strftime('%B %d,%Y')"/>
My Output is: May 28,2018
According to my experience, you have used the correct way to format Qweb date, but sometimes there is problem in other thing and odoo gives error somewhere else. Hope trying this code may be helpful.
<span t-field="o.date_order" t-field-options='{"format": "d MMMM y"}'/>
also use this code
<span t-field="o.date_order" t-field-options="{'format': 'yyyy-MM-dd'}" />
You can also do one thing as formatting the date variable in the model itself and then show it on your QWeb report.
I wanted to fetch the value 606 from the following code for selenium
<div class="price pad-15 per-person budget-pp marg-left-10 ">
<span>From</span>
<h2 class="size-28 dis-inblock">
<span class="size-22">£</span>
606
</h2>
<span>Per person</span>
</div>
Can anyone please help me with identifying xpath for the value 606. Thanks in advance.
XPath for element that contains 606 is:
//h2[span[text()="£"]]
You can fetch value with appropriate method in your programming language (like .get_attribute("text") or .text in Python')
Let me know in case of any issues
//div/h2/text() here is enough.
//text()[. = '606'] would be too (but I doubt it's what you require here!)
You can use below cssSelector as well :-
div.price.per-person > h2
(Assuming you're using Java) Now you can use WebElement#getText() to fetching the desired text after locating element using above selector, this would fetch text as £606, you can use some programming stuff to omit £ and get actual value which you want.
We are trying to display the current datetime value in XSL report along with the meridian and the timezone. I am able to achieve the same using the below tag except for the meridian. Please advice.
date:format-date(date:date-time(), 'dd/MM/yyyy hh:mm:ss Z')
Tried below, but the tt is for Microsoft date format and it is coming the same in the report and I m not able to get the expected AM or PM
date:format-date(date:date-time(), 'dd/MM/yyyy hh:mm:ss tt Z')
Since you are obviously not using XSLT 2.0, but some sort of an extension to XSLT 1.0 (perhaps EXSLT?), try:
date:format-date(date:date-time(), 'dd/MM/yyyy hh:mm:ss a Z')
If you are using XSLT 2.0, try
dd/MM/yyyy hh:mm:ssP Z
Full doc can be found here
Looks like EXSLT to me as well, in which case Michael is correct with the suggestion to use "a" to get AM/PM. If your declaration of the "date" namespace is:
xmlns:date="http://exslt.org/dates-and-times"
then that's what you're using. Implementations of EXSLT dates-and-times are supposed to support the Java JDK 1.1 SimpleDateFormat, so you can use this page as a reference. You will probably also want to refer to the exslt.org page.
I want to create the demo data on my module and use yaml to do this
and my problem is i want to create the current date on my demo
in xml
<field name="date_invoice" eval="time.strftime('%Y')+'-06-23'"/>
and my question is if i want to put in yaml what can i do ?
Some one please help me and thank you for you time to rend my word (sorry about my language :'|)
You can use
field_date: !eval time.strftime('%Y-%m-%d')
or if you want defined day code like this
field_date: !eval time.strftime('%Y-%m-24')
Is there any function that converts
<a href="test.php"/>
to
< href="test.php"/>
It would be helpful if all html characters were converted in the similar manner.
Is there a function or library to do this?
var eaten:String = myString.replace(/&/g,'&').
replace(/</g,'<').
replace(/>/g,'>').
replace(/"/g,'"');
use HttpUtility
It sounds like encodeURIComponent may be what you're after:
http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/package.html#encodeURIComponent%28%29