I see below datetimestamp in json but not sure which format is this??
20220914171900Z-0700
any suggestions??
Thanks in advance!
I used constructDateString but no luck!
2022 - yyyy (Year)
09 - MM (Month)
14 - dd (day of month)
17 - HH (Hour of day)
19 - mm (Minute of hour)
00 - ss (Second of minute)
Z-0700 - Z stands for Zulu and represents 00:00 hours offset from UTC. So, Z-0700 means an offset of 07:00 hours from UTC. If you want to get this date-time at UTC, you can do so by adding 07:00 hours to 2022-09-14T17:19.
Demo using Java:
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
class Main {
public static void main(String[] args) {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("uuuuMMddHHmmss'Z'Z");
String strDateTime = "20220914171900Z-0700";
OffsetDateTime odt = OffsetDateTime.parse(strDateTime, dtf);
System.out.println(odt);
// The same date-time at UTC
OffsetDateTime odtUTC = odt.withOffsetSameInstant(ZoneOffset.UTC);
System.out.println(odtUTC);
}
}
Output:
2022-09-14T17:19-07:00
2022-09-15T00:19Z
ONLINE DEMO
Note: You can use y instead of u here but I prefer u to y.
Learn more about the modern Date-Time API from Trail: Date Time.
Related
I want to have date of every weeks.
I put 07/02/2022 in F5 cell and put =EDATE(F5 + 7) in G5 cell
But N/A comes in G5
I guess maybe I put 07/02/2022 in F5 in a wrong way..
What should I do?
read the error message:
Wrong number of arguments to EDATE. Expected 2 arguments, but got 1 arguments.
correct G5 to =EDATE(F5,7)
In case you refer to tomorrow's date, that is 2/7/2022.
You are, if you read the help, adding 7 months with the command above.
The date of the next week starting on any day
function nextWeekDateStartingOnThis(day = 1) {//Sun(0) - Sat(6)
let dt = new Date();
let nd = new Date(dt.getFullYear(), dt.getMonth(), dt.getDate() + 7 - dt.getDay() + day);
Logger.log(nd);
return nd;//this returns the date of the next monday because day = 1
}
If you want the date of the next tuesday then make day = 2
I need to convert month number to month name.
I have date time as the date type - 2009-01-01 00:00:00.000
I also have 4-byte integer data type - 1
how do I convert this 1 to "January" for example?
i think you are in the data flow:
it is really easy to get MOnth Name in a script component from Date:
add a varchar column to your dataflow
Mark your date column for read access
enter the following script
Row.[NewColumnName] = Row.[Your Date Column].ToString("MMMM");
Result:
Here is a good translations for any date part to string formatting:
// create date time 2008-03-09 16:05:07.123
DateTime dt = new DateTime(2008, 3, 9, 16, 5, 7, 123);
String.Format("{0:y yy yyy yyyy}", dt); // "8 08 008 2008" year
String.Format("{0:M MM MMM MMMM}", dt); // "3 03 Mar March" month
String.Format("{0:d dd ddd dddd}", dt); // "9 09 Sun Sunday" day
String.Format("{0:h hh H HH}", dt); // "4 04 16 16" hour 12/24
String.Format("{0:m mm}", dt); // "5 05" minute
String.Format("{0:s ss}", dt); // "7 07" second
String.Format("{0:f ff fff ffff}", dt); // "1 12 123 1230" sec.fraction
String.Format("{0:F FF FFF FFFF}", dt); // "1 12 123 123" without zeroes
String.Format("{0:t tt}", dt); // "P PM" A.M. or P.M.
String.Format("{0:z zz zzz}", dt); // "-6 -06 -06:00" time zone
Furthermore, you asked about quarters. I don't think it is as easy but here is something I stole from another answer.
Build DateTime extensions:
Normal Quarter:
public static int GetQuarter(this DateTime date)
{
return (date.Month + 2)/3;
}
Financial Year Quarter (This case is for quarters that start on April 1):
public static int GetFinancialQuarter(this DateTime date)
{
return (date.AddMonths(-3).Month + 2)/3;
}
Integer division will truncate decimals, giving you an integer result. Place methods into a static class and you will have an extension method to be used as follows:
Row.calendarQuarter = Row.[your Date Column].GetQuarter()
Row.fiscalQuarter = Row.[your Date Column].GetFinancialQuarter()
In SQL Server, one method is:
select datename(month, datefromparts(2000, 1, 1))
The first "1" is the column for the month. The year is arbitrary.
following steps:
create variable with datetime datatype and assigned value.
used MONTH function in ssis to extract month number and assigned to new variable with integer data type: #[User::newdata]= MONTH( #[User::dbdate])
finally used if else condition which manually compare all 12 months
(code available:1)
I want to get the current day using dart.
Code I want:-
//I want something like this
var day = DateTime.getCurrentDay();
Output:-
Tuesday
use this pattern
DateFormat('EEEE').format(yourDate);
or
DateFormat('EEEE').format(DateTime.now());
See all available patterns here
ICU Name Skeleton
-------- --------
DAY d
ABBR_WEEKDAY E
WEEKDAY EEEE
ABBR_STANDALONE_MONTH LLL
STANDALONE_MONTH LLLL
NUM_MONTH M
NUM_MONTH_DAY Md
NUM_MONTH_WEEKDAY_DAY MEd
ABBR_MONTH MMM
ABBR_MONTH_DAY MMMd
ABBR_MONTH_WEEKDAY_DAY MMMEd
MONTH MMMM
MONTH_DAY MMMMd
MONTH_WEEKDAY_DAY MMMMEEEEd
ABBR_QUARTER QQQ
QUARTER QQQQ
YEAR y
YEAR_NUM_MONTH yM
YEAR_NUM_MONTH_DAY yMd
YEAR_NUM_MONTH_WEEKDAY_DAY yMEd
YEAR_ABBR_MONTH yMMM
YEAR_ABBR_MONTH_DAY yMMMd
YEAR_ABBR_MONTH_WEEKDAY_DAY yMMMEd
YEAR_MONTH yMMMM
YEAR_MONTH_DAY yMMMMd
YEAR_MONTH_WEEKDAY_DAY yMMMMEEEEd
YEAR_ABBR_QUARTER yQQQ
YEAR_QUARTER yQQQQ
HOUR24 H
HOUR24_MINUTE Hm
HOUR24_MINUTE_SECOND Hms
HOUR j
HOUR_MINUTE jm
HOUR_MINUTE_SECOND jms
HOUR_MINUTE_GENERIC_TZ jmv (not yet implemented)
HOUR_MINUTE_TZ jmz (not yet implemented)
HOUR_GENERIC_TZ jv (not yet implemented)
HOUR_TZ jz (not yet implemented)
MINUTE m
MINUTE_SECOND ms
SECOND s
// DateTime.now() or any DateTime format can be used.
DateFormat('EEEE').format(DateTime.now());
To use other Date formats/patterns like "EEEE" you can visit the Official Documentation
I am receiving a json which I convert to DataFrame df. One of the column is with Dates this format
/Date(950842800000)/, /Date(1000436400000)/, ...
The problem is that One of this dates has 12 digit and the others 13 digits. This one with 13 digits are converted fine, and with 12 there is a problem. The way I am converting
df["Data"] = df["Date"].apply(lambda x: datetime.fromtimestamp(int(x[6:-2][:10])) if len(x) > 12 else datetime.fromtimestamp(int(x[6:-2][:11])))
doesn´t work for 12 digits.
Thank You for help.
Short:
lambda x: datetime.fromtimestamp(int(x[6:-2][:-3]))
Long:
If you have such input data:
"/Date(950842800000)/",
"/Date(1000436400000)/"
Than a few modifications will make script working correctly:
from datetime import datetime
dates = [
"/Date(950842800000)/",
"/Date(1000436400000)/"
]
for d in dates:
l = lambda x: datetime.fromtimestamp(int(x[6:-2][:9])) if len(x) < 21 else datetime.fromtimestamp(
int(x[6:-2][:10]))
print(l(d))
produce:
2000-02-18 04:00:00
2001-09-14 05:00:00
what is what you expect.
But then we may think to simplicity, you may just use:
from datetime import datetime
dates = [
"/Date(950842800000)/",
"/Date(1000436400000)/"
]
for d in dates:
l = lambda x: datetime.fromtimestamp(int(x[6:-2][:-3]))
print(l(d))
I am using Rails 4. I've read 2 records(b1 and b2) from database. Both them have a column called build_start_time, which is defined as datetime type in Mysql. The build_start_time between b1 record and b2 record are like this:
2.0.0-p643 :021 > b1.build_start_time
=> Tue, 12 Aug 2014 18:23:31 UTC +00:00
2.0.0-p643 :012 > b2.build_start_time
=> Fri, 15 Aug 2014 10:07:18 UTC +00:00
How do I calculate the duration between them in Rails ? Does anybody have an idea?
The result should be something like:
b2.build_start_time - b1.build_start_time = 2 days 15 hours 53 minutes 47 seconds
Is this possible?
Assuming you can tolerate your answer being off by less than a second you could try using the to_i and ago methods:
def datetime_diff(datetime1, datetime2)
res = datetime1 <=> datetime2
if res == 0
# order doesn't matter in this case
min = datetime1
max = datetime2
elif res < 0
min = datetime1
max = datetime2
else
min = datetime2
max = datetime1
end
max.ago(min.to_i) # min.to_i returns min in seconds since the epoch
end
You figure out which time came first then you return the later of the two times x seconds ago, where x is the earlier time in seconds since the epoch. See http://api.rubyonrails.org/classes/DateTime.html#method-i-3C-3D-3E