Convert any time string to INDIAN time or INDIA time and date (convert string to indian timezone) using Python3 - python-datetime

I have a simple problem to convert any kind of date time string into INDIAN date time string or you can say convert to Indian timezone but unable to find an exact approach

so here is the exact answer
import pytz
from dateutil import parser
IST = pytz.timezone('Asia/Kolkata')
tzdate = parser.parse('2019-04-21T10:38:16.000Z')
print(tzdate.astimezone(IST).isoformat())
In this first you are importing "pytz" which is python package for getting time zone of any country using string by which I am getting IST in 3rd line.
After that, I parsed the date and time string in the fourth line.
And after implementing all I assign IST as time zone during printing date and time.

Related

What is the time format in chrome dev tools cache Expires/ Max-Age?

I noticed the time format in chrome cache expiry is in format of 2021-06-19T08:38:40.980Z.
I do not recognize this time format and cant find about its conversion to UTC. So, my question is what kind of time format is this one. And how to convert it to UTC?
That is the ISO 8601 extended date time format. It also conforms to the RFC 3339 timestamp format, and the ECMAScript date time string format. Basically, that's the standard, most preferred way to represent a timestamp (as a string) on the Internet.
The date part is in yyyy-MM-dd format (year, month, day).
The T stands for "Time" and separates the date part from the time part.
The time is in HH:mm:ss.fff format (hour of 24-hour clock, minute, seconds, fractional seconds - milliseconds in this case).
The Z stands for "Zulu", another name for UTC. It indicates that the date and time before it are represented in UTC.
Thus, you do not need to convert it. The value is already in UTC.

Date conversation with time zone information

I have one issue. Solutions might be there already in this forum but I couldn't find anything. Please share if it's already answered.
The scenario is as below.
Request is coming in CET to my application which is running in UTac time zone. My backend stored procedure is running in CET zone. The time that is passed in as string with cet offset I need to send same as SQL date with same date to my backend.
Current implementation is:
Convert string date to offsetdate. Then create Instant from that offsetdate and then util date using that instant. Once I have until date I am converting that to SQL Date.
So here issue is if input request us 2012-07-15T00:00:00+02:00 then when applications which is running in UTC is giving correct offset date with cet offset information but when it is converting to instant then always UTC will come. So new date is 2012-07-14T00:00:00Z and because if this my util and SQL date is also coming 1 day behind.
Can anyone please guide if there is any other way where I can create SQL or util. Date for same date irrespective of any time zone?
Because the expectation is request can come with any time zone and we need to understand that zone and then convert or use accordingly and same date should go to back end.
API developed with: Spring boot with JAVA 8 and backend we are accessing using stored procedure where stored procedure is expecting in SQL date.
Since you can use OffsetDate and other classes from java.time, the modern Java date and time API, you should no longer be using java.util.Date nor java.sql.Date. Those classes are poorly designed and long outdated, and the modern API offers all the functionality you need. You might have thought that you needed a java.sql.Date for storing into your SQL database. But with JDBC 4.2 (or a newer JPA implementation such as Hibernate) you can directly store a LocalDate there, which you will prefer.
String requestString = "2012-07-15T00:00:00+02:00";
OffsetDateTime dateTime = OffsetDateTime.parse(requestString);
LocalDate date = dateTime.toLocalDate();
System.out.println("Date is " + date);
This prints:
Date is 2012-07-15
No day has gone lost. To save do for example:
PreparedStatement ps = yourDatabaseConnection.prepareStatement(
"insert into your_table (your_date) values (?);");
ps.setObject(1, date);
ps.executeUpdate();
Sometimes we need to pass an old-fashioned type to a legacy API that we cannot afford to change right away. If this was your reason for wanting a java.sql.Date, convert like this:
java.sql.Date sqlDate = java.sql.Date.valueOf(date);
System.out.println("Old-fashioned java.sql.Date is " + sqlDate);
Old-fashioned java.sql.Date is 2012-07-15
Still no day is lost.
Edit: If what your legacy API requires is a java.util.Date, you will need to know the way to convert:
Instant startOfDay = date.atStartOfDay(ZoneId.systemDefault()).toInstant();
Date oldFashionedUtilDate = Date.from(startOfDay);
System.out.println("As old-fashioned java.util.Date: " + oldFashionedUtilDate);
When I run with a default time zone UTC the output is:
As old-fashioned java.util.Date: Sun Jul 15 00:00:00 UTC 2012

How to get the week day name from a date in Apache pig?

Given "03/09/1982" how can we say it is which week day. In this case it will be "Tue".
Is it possible to get in a single query?
Thanks
You can convert this string into date object using ToDate(), then again into string with desired format using ToString(), and dont forget that Pig uses Java SimpleDateFormat class to deal with dates.
ToString( ToDate('03/09/1982','dd/MM/yyyy'), 'EEE' )

how to convert this string '2014-12-31T05:00:00.000+00:00' into date in informatica

i have my date coming in string form :'2014-12-31T05:00:00.000+00:00'
how can TO convert this into date format in informaticA
Take a sub string of the time string '2014-12-31T05:00:00.000+00:00' to '2014-12-31' after all you need date part only.
Then parse the date using to_date method.
to_date('substring date','yyyy-dd-mm')
You can use this:
to_date('2014-12-31T05:00:00.000+00:00', 'YYYY-MM-DD.HH:MI:SS.MS......')
Keep in mind that it ignores the time zone information.

How to find a date and time stamp in a file using VBscript?

I have an online temperature logger that publishes the date and time of last measurement in a file.
I need to find the date and time stamp in the html file using VBscript, and then check if it's older then 2 hours comparing to current time.
Example date format: 12.04.2013 16:45
You could extract the timestamp with a regular expression
\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}
However, due to the characteristics of HTML this is prone to error (line-wrapping, inline tags, …), so a better approach would be to extract the date from the HTML using DOM methods (e.g. getElementsByTagName().
Once you have the date string, you can use the DateDiff function to calculate the difference to the current timestamp:
DateDiff("h", datestring, Now)

Resources