[Solved] Java gives me wrong time every time i try to get it [closed]

This answer has some of the time zones to use in your getTimeZone method. Calendar curTime = new GregorianCalendar(); curTime.setTimeZone(TimeZone.getTimeZone(“Europe/Kiev”)); DateFormat dateFormat = new SimpleDateFormat(“HH:mm”); dateFormat.setCalendar(curTime); String time = dateFormat.format(curTime.getTime()); System.out.println(time); Output: 19:22 1 solved Java gives me wrong time every time i try to get it [closed]

[Solved] Generate month data series with null months included?

You can generate all starts of months with generate_series(), then bring the table with a left join: select to_char(d.start_date, ‘mon’) as month, extract(month from d.start_date) as month_num, sum(cost_planned) filter (where t.aasm_state in (‘open’, ‘planned’ ) ) as planned, sum(cost_actual) filter (where t.aasm_state=”closed”) as actual from generate_series(‘2020-01-01’::date, ‘2020-12-01’::date, ‘1 month’) d(start_date) left join activity_tasks t on … Read more

[Solved] php mysql car parking query [closed]

Your query is referencing return_date, which isn’t a column in the airport_car_parking table. As for the logic of the query, you want to make sure that the $departure_date isn’t between any row’s departure_date or arrival_date. I would recommend the following query – $chk_date_sql=”SELECT * FROM airport_car_parking WHERE ‘$departure_date’ BETWEEN departure_date AND arrival_date;”; And then that … Read more

[Solved] Inserting ISO date in sql server

@dlatikay! based on your first comment i changed the datatype from DateTime to string and it worked. dTable.Columns.Add(“created_on”, typeof(string)); When the datatype is DateTime,the result is coming as expected,but on insertion to sql the value is changing.Now, while iam sending the value as string to sql,it is converting that string to DateTime and it worked. … Read more

[Solved] Converting DateTime string in ddd MMM dd HH:mm:ss ‘EST’ yyyy format?

In my controller I do the following now. var startDateTZ = _startDate.Substring(20, 4); if (startDateTZ[3] == ‘ ‘) { startDateTZ = _startDate.Substring(20, 3); } if (startDateTZ.Length > 3) { if (startDateTZ[3] == ‘0’) { startDateTZ = _startDate.Substring(19, 4); } if (startDateTZ[3] == ‘2’) { startDateTZ = _startDate.Substring(19, 3); } } var startDate = new DateTime(); … Read more

[Solved] Check season of year in php

Just need to format the values o match yours $someDay = “2018-12-01”; $spring = (new DateTime(‘March 20’))->format(“Y-m-d”); $summer = (new DateTime(‘June 20’))->format(“Y-m-d”); $fall = (new DateTime(‘September 22’))->format(“Y-m-d”); $winter = (new DateTime(‘December 21’))->format(“Y-m-d”); switch(true) { case $someDay >= $spring && $someDay < $summer: echo ‘It\’s Spring!’; break; case $someDay >= $summer && $someDay < $fall: echo … Read more

[Solved] PHP 01/01/1970 Issues with Date Fields

Use below code $current=”DATE OF : 23/03/1951 BENCH:”; $DATEOF = preg_replace(‘/(.*)DATE OF (.*?)BENCH:(.*)/s’, ‘$2’, $current); if (!is_null($DATEOF)) { $oldDate = $DATEOF; $oldDateReplace = str_replace(array(‘!\s+!’, ‘/^\s+/’, ‘/\s+$/’,’:’), array(”,”,”,”), trim($oldDate)); $date=””.$oldDateReplace.”; $timestamp = strtotime($date); if ($timestamp === FALSE) { $timestamp = strtotime(str_replace(“https://stackoverflow.com/”, ‘-‘, $date)); } echo $newDateM = date(“m/d/Y”,$timestamp); echo $newDate = date(“F j, Y”,$timestamp); }else{$newDate=””;} 5 … Read more

[Solved] How to subtract time with current time

The time difference (in milliseconds) can be obtained using: ChronoUnit.MILLIS .between(Instant.parse(“2018-07-26T16:00:17.163Z”), Instant.now()) Instant.now() will be the current UTC time, and your input date is UTC time, which makes the diff sensible. Regardless of the current time zone, the difference will be consistent. You can change the time unit accordingly (such as ChronoUnit.HOURS). 0 solved How … Read more

[Solved] Subtract 6 hours from an existing Date object java (midnight corner case)

No. After running the following code: Date birthDate = (…say Apr 20th 0300hrs) Calendar cal = Calendar.getInstance(); cal.setTime(birthDate); cal.add(Calendar.HOUR, -6); you are guaranteed that cal is set to six hours before ‘Apr 20th 0300hrs’, but not that it is set to ‘Apr 19th 2100hrs’. 4 solved Subtract 6 hours from an existing Date object java … Read more

[Solved] Programmatically get the time at clock-change [closed]

To find out DST transitions, you could access Olson timezone database e.g., to find out the time of the next DST transition, in Python: #!/usr/bin/env python from bisect import bisect from datetime import datetime import pytz # $ pip install pytz def next_dst(tz): dst_transitions = getattr(tz, ‘_utc_transition_times’, []) index = bisect(dst_transitions, datetime.utcnow()) if 0 <= … Read more

[Solved] Why is DateTime.TryParse making my number into a Date?

public static class DBNullExt { public static string DBNToString(this object value) { if (value == System.DBNull.Value) return null; else { string val = value.ToString(); DateTime test; string format = “MM/dd/yyyy h:mm:ss tt”; if (DateTime.TryParseExact(val, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out test)) return test.ToShortDateString(); else return val; } } } As a string, 3685.02 or 2014.10 is an … Read more