I need to display the below "String" in the desired format
String str = 1979-01-24T00:00:00.000-08:00
Desired format: Jan 24, 1979 00:00:00 AM PST
Note: The tz in the str could be any tz not limited to PST.
Tried the below but none worked:
str?datetime.iso - Output is Jan 24, 1979 2:00:00 AM CST - This displays the date time in the format I need but the time is being converted from PST to CST.
str?string("MMM dd, yyyy hh:mm:ss a zzz") - Error: Expected a method, but this has evaluated to a string
str?datetime?string("MMM dd, yyyy hh:mm:ss a zzz") - Error: Unparseable date: "1979-01-24T00:00:00.000-08:00"
<#setting datetime_format="iso"> str?datetime - 1979-01-24T02:00:00-06:00 - The timezone is changed.
The problem here is that FreeMarker parses date/time values to java.util.Date (and its subclasses), which don't store a time zone anymore, as it always stores the value in UTC. So that information is lost after parsing. As of 2.3.30, the only solution I see to do this in Java (with Java 8 ZonedDateTime).
The timezone can be configured by the following setting, as refer to their documentation https://freemarker.apache.org/docs/ref_directive_setting.html
<#setting time_zone ="PST">
<#assign str = "1979-01-24T00:00:00.000-08:00">
${str?datetime.iso}
Not able to parse a date string into a Pandas date.
I have tried various formats for the date, however, I can't figure out a way to easily debug it as opposed to guessing.
test = pd.to_datetime('Thu Mar 21 18:24:35 +0000 2019', format=('%A %B %d %H:%M:%S','+0000', '%Y'))
ValueError: time data 'Thu Mar 21 18:24:35 +0000 2019' doesn't match format specified
For certain versions of pandas (I tested with 0.24.1), it should work without specifying format:
test = pd.to_datetime('Thu Mar 21 18:24:35 +0000 2019')
There are, however, issues with your format string. For one, I'm not sure why you're provided a tuple rather than one continuous string. For two, you use '%A' and %B' - in datetime formatting, these provide the weekday and month as the full name in both cases (source). In your case, you have the abbreviated names - '%a' and '%b'. So the following should work:
test = pd.to_datetime('Thu Mar 21 18:24:35 +0000 2019', format='%a %b %d %H:%M:%S +0000 %Y')
I am trying to copy values across 2 datetime fields. While copying I want to set the time to 9:00 PM and pass the date value as it is.
Can anyone help on how to do this
I'm not sure I understand your question, but if you want to set the time component of a java.util.Date to 9PM, this should do it
Date date = new Date()
date.clearTime()
date.set((Calendar.HOUR_OF_DAY): 21)
However, this modifies the source Date object in-place. To avoid this, use the following instead:
Date date = new Date()
Date dateAt9PM = new Date(date.getTime()).clearTime()
dateAt9PM.set((Calendar.HOUR_OF_DAY): 21)
You can also use some groovy magic (C)
Date orig = new Date() + 10
Datew newDate = orig.updated( hourOfDay:19, minute:42, second:33 )
gives
Sat Mar 23 19:42:33 UTC 2019
I have this kinf of date format :
Mon, Nov 19, 2018
And I want it in a french short date format (DD/MM/YYY)
But i can't resolve it with basic date format with excel.
Any ideas ?
You can use MATCH to return the correct month:
=DATE(RIGHT(A1,4),MATCH(TRIM(MID(A1,FIND(" ",A1)+1,3)),{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"},0),MID(A1,FIND("}}}",SUBSTITUTE(A1," ","}}}",2))+1,2))
To convert your text into a date, you can use this formula (assuming the date in text format is in cell C15):
=DATE(RIGHT(C15,4),IF(EXACT(MID(C15,6,3),"Jan"),01,IF(EXACT(MID(C15,6,3),"Feb"),02,IF(EXACT(MID(C15,6,3),"Mar"),03,IF(EXACT(MID(C15,6,3),"Apr"),04,IF(EXACT(MID(C15,6,3),"May"),05,IF(EXACT(MID(C15,6,3),"Jun"),06,IF(EXACT(MID(C15,6,3),"Jul"),07,IF(EXACT(MID(C15,6,3),"Aug"),08,IF(EXACT(MID(C15,6,3),"Sep"),09,IF(EXACT(MID(C15,6,3),"Oct"),10,IF(EXACT(MID(C15,6,3),"Nov"),11,IF(EXACT(MID(C15,6,3),"Dec"),12)))))))))))),MID(C15,10,2))
Then you get an Excel date that is easier to work with.
Am making a request to CryptoCompare API, and the data is parsed to my ejs template, i want the last update object key value to be shown in my template all i get is a number(62837329), and i used new Date() function to parse the date and it gave me a very wrong date.
How I parsed the date in my ejs template
<p> <%= new Date(display.RAW.ETH.USD.LASTUPDATE) %></p>
The date format that is shown in my template, if possible i wish it is in short date format
Sun Jan 18 1970 15:27:56 GMT+0000 (UTC)
I believe the CryptoCompare API is returning a timestamp in seconds from Jan 1, 1970 where the JavaScript Date expects a timestamp in milliseconds from Jan 1, 1970. Therefore you should multiply the number fetched by 1000.
<p> <%= new Date(display.RAW.ETH.USD.LASTUPDATE * 1000) %></p>
As far as formatting goes I would recommend Moment.js as a great way to easily format dates to your liking.