Convert TimeStamp To Joda DateTime Without Any Timezone Conversion - spring

I have timestamp value in Oracle database column stored in UTC. I want to read it through spring's jdbcTemplate and convert it to joda DateTime object without any timezone conversion i.e. read it as is without converting or losing timezone.
For e.g. if the input timestamp is 2019-03-08 15:07:37.232, I would like to have the DateTime object with the value 2019-03-08T15:07:37.232Z
How can I achieve this?
Note this code - new DateTime(timestamp.getTime(), DateTimeZone.UTC)) does not help since it assumes that the input timestamp is in local timezone and reconverts it to UTC. For the above input is 2019-03-08 15:07:37.232 the outcome comes to 2019-03-08T09:37:37.232Z
Thanks.

One solution that worked was to change the way the timestamp column value is retrieved from the database. The below snippet works for converting a timestamp column value to joda DateTime without losing/converting the timezone
new DateTime(resultSet.getTimestamp("CreatedDateTime",
Calendar.getInstance(TimeZone.getTimeZone("UTC"))), DateTimeZone.UTC)
Hope that helps others too.

If you already have a DateTime object there is method
public DateTime withZone(DateTimeZone newZone)
which would return a copy of datetime with a different time zone, preserving the millisecond instant
eg:- dateTime.withZone(DateTimeZone.UTC)

Related

How to serialize Date and DateTime with URQL?

I am using urql-react as my React client in a project. I need to make sure that any date variables in query/mutation with Date scalar type are serialized into YYYY-DD-MM format while for DateTime scalar type, the date object is serialized in YYYY-DD-MMTHH:mm:ssZ format.
How can this be achieved on a central level?

Can't remove hours and minutes from datatable

I'm trying to get release date field with y-m-d format.. Actually time format (for y-m-d) seems fine but also it gives h:m:s too, I changed time format at server side and removed h:m:s but datatable still shows them
What I get
2012-04-11 00:00:00
What I want
2012-04-11
Released_at field (Metronic theme - json datatable)
{
field: "released_at",
title: "Release Date",
type: "date",
format: "YYYY/MM/DD"
}
time format (I'm using laravel framework)
protected $dateFormat = "Y-m-d";
How do I fix this ?
Datatable accept column type same as mysql type.
You are trying to convert mysql dateTime column to Date in datatable, which is not possible from datatable.
In your code you have declared
format: "YYYY/MM/DD" // but actual type is dateTime as per mysql.So it will append time next to it.
If you are storing only date in mysql then you can change column type to Date, and your problem gets solved.
And if you want to convert string to date in laravel you can follow this post.
Your database column is of type dateTime which, by definition, includes both date and time information. If you want to remove the time at a database level then use the date type instead
$table->date("released_at")->nullable();
If instead of removing the time from the database, you just want to ignore it for certain parts of your application, you can leverage the fact than in Laravel all dates coming from your models are Carbon\Carbon instances, so you could do
$model->releasedAt->format('y-m-d'); // Returns '18-09-11'

TO_TIMESTAMP_TZ Functionality

Any one have any idea how 'TO_TIMESTAMP_TZ' function works internally in oracle.
I want to know how it converts timestamp to timezone
The documentation is very handy for questions like this.
TO_TIMESTAMP_TZ converts a string into a timestamp with timezone information. It doesn't convert something that's already a timestamp into a timestamp with timezone information, without first having a conversion back into a string - which, as I'm sure you're aware, you should always do explicitly.

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.

Hive dataype for date

Date;Time;Global_active_power;Global_reactive_power;Voltage;Global_intensity;Sub_metering_1;Sub_metering_2;Sub_metering_3
16/12/2008;17:24:00;4.216;0.418;234.840;18.400;0.000;1.000;17.000
16/12/2008;17:25:00;5.360;0.436;233.630;23.000;0.000;1.000;16.000
16/12/2008;17:26:00;5.374;0.498;233.290;23.000;0.000;2.000;17.000
16/12/2008;17:27:00;5.388;0.502;233.740;23.000;0.000;1.000;17.000
16/12/2008;17:28:00;3.666;0.528;235.680;15.800;0.000;1.000;17.000
16/12/2008;17:29:00;3.520;0.522;235.020;15.000;0.000;2.000;17.000
16/12/2008;17:30:00;3.702;0.520;235.090;15.800;0.000;1.000;17.000
16/12/2008;17:31:00;3.700;0.520;235.220;15.800;0.000;1.000;17.000
16/12/2008;17:32:00;3.668;0.510;233.990;15.800;0.000;1.000;17.000
This is the sample data, i am really confused with the datatype to be used for Date and Time.
plese help,
You probably want to be looking at the TimeStamp datatype which has this format:yyyy-mm-dd hh:mm:ss
There is also a Date datatype which takes this format: YYYY-­mm-­dd
There isn't a seperate time datatype. If you can't change the sample data you probably want to load the dates as string and use udfs like unix_timestamp(string date, string pattern) then copy to result into a new table.

Resources