I have a seconds variable. How to convert its content to hours, days and weeks?
{assign var="formin" value="{$sec/60}"}
{$formin}
You should use date object with date_format (ex. {$smarty.now|date_format:"%D"}) because you can use conversion specifiers with it. More about that here: https://www.smarty.net/docsv2/en/language.modifier.date.format.tpl
If you still want to convert seconds to weeks in your template you can put calculations in smarty brackets:
{$sec/60}
{$sec/(60*60*24)}
{$sec/(60*60*24*7)}
Optionaly you can use string_format to round it up (ex. {$sec/(60*60*24*7)|string_format:"%d"}): https://www.smarty.net/docsv2/en/language.modifier.string.format.tpl
Related
Problem:
I have got a directory of files, which have a creation date.
What I am trying to reach is to get the value of the creation date day, month and year.
However, I am working with a FileTime.
I was expecting to be able to call a GetMonth method or such.
Unfortunately, this is not possible, does someone know a nice solution to get the day/month/year of a FileTime?
What have I tried:
I have tried to convert this to the Date type. This is possible, but here are the day, month and year methods deprecated.
I have tried to use to get the milliseconds of the FileTime, but this did not feel like a pretty solution.
Final question:
How do I get the day, month and year of a FileTime?
Thanks in forward.
FileTime ➙ Instant ➙ ZonedDateTime
I'm assuming that you're using Java 8 or later. You must convert the FileTime to an Instant. You can then apply a ZoneId to the Instant to get a ZonedDateTime object for the time zone you want the date in. The below code converts the FileTime to date in India time.
val zonedTime = fileTime.toInstant().atZone(ZoneId.of("Asia/Kolkata"))
println(zonedTime.year)
println(zonedTime.monthValue)
println(zonedTime.dayOfMonth)
I would like parse a String
'16:25:20.6598412Z'
as TIMESTAMP WITHOUT TIME ZONE
The function which I use is:
TO_TIMESTAMP('16:25:20.6598412Z', 'HH24:MI:SS.MSUS')
but the result is:
16:25:21.5002+01
this have not the same time:
16:25:20.6598412
You cannot use MS and US both in one to_timezone call - microseconds are miliseconds also (and a little more) so how engine would know how to parse the string?
Instead you should use
TO_TIMESTAMP('16:25:20.6598412Z', 'HH24:MI:SS.US')
also notice that microseconds due to reference is value in range of (000000-999999) so you can pass 6 digits as US
TO_TIMESTAMP('16:25:20.659841Z', 'HH24:MI:SS.US')
To loose timezone simply add ::timestamp without time zone; at the end of to_timestamp call
TO_TIMESTAMP('16:25:20.6598412Z', 'HH24:MI:SS.MSUS')::timestamp without time zone;
I want to use the today() function as a dynamic filter to show MM/YYYY as number format
So i want my filter to show =201601
But with my function i get 20161: input(CATS(Year(TODAY()),Month(TODAY())), 6.) =20161
Does anybody know how to show 201601 instead of 20161?
There is a format that will display a data in YYYYMM format.
put(today(),yymmn6.)
Did you intend to convert to a number instead of a character string? If so then you could use the INPUT function as in your example.
input(put(today(),yymmn6.),6.)
You could even use the YYMMDDN format if YYMMN doesn't work for you, just read the first 6 digits.
input(put(today(),yymmddn8.),6.)
Or you could build the number arithmetically.
year(today())*100+month(today())
Here's the proper function:
put(today(), yymmn6.)
NSDate *createDate = [NSDate dateWithTimeIntervalSince1970:1376460694.103];
NSLog(#"createDate %#",createDate);
I am using the above code to get the current date and time,when I put break point at createDate,It shows correct time stamp value,but NSLog(#"createDate %#",createDate) statement is printing the date as 2013-08-14 06:11:34 +0000.
How to get the correct result?
The date is correct. When printing to the console the description of the date is used and that uses your system locale so it applies your time zone to the date before printing.
When you want to display the time you need to use a date formatter to convert the date into a string. The important part is setting the locale / time zone that the formatter uses.
Take a read of this and this.
I have a date time as a string, eg. "2010-08-02", I'm trying to convert it to UTC with the following code snippet
DateTime.ParseExact("2010-08-02Z", "yyyy-MM-ddZ", CultureInfo.InvariantCulture)
When I print to the console, I get the following: 8/1/2010 5:00:00 PM.
Is there a reason why the date shows up as the date before the date I'm trying to parse? I could just add a day to this to advance to the original day, but I wanted to see if there's anything I'm doing wrong in the formatting that's causing this.
EDIT: I had a mixture of being correct and not :)
It's showing you the local time represented by the UTC string. It's annoying that DateTime doesn't make this sort of thing clear, IMO. Additionally, I don't think you want to use 'Z' as the format specifier for the time zone; that's not actually a valid format specifier; it should be 'z', - but that's meant for things like "+01:00". I think you should be using 'K'. Frankly it's not clear, but if you use 'K' it round-trips correctly, certainly ('Z' roundtrips too, but only because it ignores it, treating it as plain text).
You can fix it by just calling ToUniversalTime, or (preferred IMO) specifying DateTimeStyles.AdjustToUniversal as an extra argument:
DateTime dt = DateTime.ParseExact("2010-08-02Z", "yyyy-MM-ddK",
CultureInfo.InvariantCulture,
DateTimeStyles.AdjustToUniversal);
The UTC of midnight for 2010-08-02 happens to be at 5pm on 2010-08-01.
If the original string is just a date in the format "2010-08-02" (without the Z), then why not just:
DateTime.SpecifyKind(
DateTime.ParseExact("2010-08-02",
"yyyy-MM-dd",
CultureInfo.InvariantCulture),
DateTimeKind.Utc);
ParseExact will presumably return a DateTime with Kind = Unspecified, and you can make it UTC or Local as you wish using SpecifyKind.