date

Java parsing date with timezone from a string

你。 提交于 2020-12-02 18:49:49
问题 I want to parse a date with timezone from a string in the format "31-12-2014 18:09 +05:30" . I tried to parse using simple-Date-Format using "d-MM-yyyy HH:mm ZZ" and "d-MM-yyyy HH:mm Z" . But it is giving me a un-parables date exception. How to do this? Please help me. 回答1: SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm XXX"); Date d = sdf.parse("31-12-2014 18:09 +05:30"); System.out.println(d); Note that you can't use X before SimpleDateFormat of JDK7, because it's the ISO

Java parsing date with timezone from a string

▼魔方 西西 提交于 2020-12-02 18:49:01
问题 I want to parse a date with timezone from a string in the format "31-12-2014 18:09 +05:30" . I tried to parse using simple-Date-Format using "d-MM-yyyy HH:mm ZZ" and "d-MM-yyyy HH:mm Z" . But it is giving me a un-parables date exception. How to do this? Please help me. 回答1: SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm XXX"); Date d = sdf.parse("31-12-2014 18:09 +05:30"); System.out.println(d); Note that you can't use X before SimpleDateFormat of JDK7, because it's the ISO

How to set the “first day of the week” to Thursday in PHP

隐身守侯 提交于 2020-12-02 06:59:47
问题 I want to set the first day of the week to Thursday (not Sunday or Monday), because it's the company's cut-off date. I already have a code to determine the current week number of a date but it starts in Sunday or Monday. How to modify these to my preference? function findweek($date) { $monthstart=date("N",strtotime(date("n/l/Y",strtotime($date)))); $newdate=(date("j",strtotime($date))+$monthstart)/7; $ddate=floor($newdate); if($ddate != $date) { $ddate++; } return $ddate; } 回答1: http://php

How to set the “first day of the week” to Thursday in PHP

送分小仙女□ 提交于 2020-12-02 06:54:51
问题 I want to set the first day of the week to Thursday (not Sunday or Monday), because it's the company's cut-off date. I already have a code to determine the current week number of a date but it starts in Sunday or Monday. How to modify these to my preference? function findweek($date) { $monthstart=date("N",strtotime(date("n/l/Y",strtotime($date)))); $newdate=(date("j",strtotime($date))+$monthstart)/7; $ddate=floor($newdate); if($ddate != $date) { $ddate++; } return $ddate; } 回答1: http://php

Get all days and date for a given month

落花浮王杯 提交于 2020-12-01 07:33:31
问题 Would like to retrieve all days and date for a given month. Have this currently which shows all the days for the current month, but how do I parse in a specified month instead? $list=array(); for($d=1; $d<=31; $d++) { $time=mktime(12, 0, 0, date('m'), $d, date('Y')); if (date('m', $time)==date('m')) $list[]=date('Y-m-d-D', $time); } echo "<pre>"; print_r($list); echo "</pre>"; 回答1: try this $list=array(); $month = 12; $year = 2014; for($d=1; $d<=31; $d++) { $time=mktime(12, 0, 0, $month, $d,

Get all days and date for a given month

蹲街弑〆低调 提交于 2020-12-01 07:32:37
问题 Would like to retrieve all days and date for a given month. Have this currently which shows all the days for the current month, but how do I parse in a specified month instead? $list=array(); for($d=1; $d<=31; $d++) { $time=mktime(12, 0, 0, date('m'), $d, date('Y')); if (date('m', $time)==date('m')) $list[]=date('Y-m-d-D', $time); } echo "<pre>"; print_r($list); echo "</pre>"; 回答1: try this $list=array(); $month = 12; $year = 2014; for($d=1; $d<=31; $d++) { $time=mktime(12, 0, 0, $month, $d,

How to take the differences between two dates, depending on the date of birth [duplicate]

混江龙づ霸主 提交于 2020-11-30 00:18:16
问题 This question already has answers here : How can I calculate the number of years between two dates? (20 answers) Closed 3 months ago . My code: function test(val) { year = parseInt(val.slice(0,2)); // get year month = parseInt(val.slice(2,4)); // get month date = val.slice(4,6); // get date if (month > 40) { // For people born after 2000, 40 is added to the month. (it is specific for my case) year += 2000; month -= 40; } else { year += 1900; } date = new Date(year, month-1, date, 0, 0); date

Removing expired dates from an array with PHP

随声附和 提交于 2020-11-29 10:34:59
问题 I have an array of dates formatted in 'm/d/Y' (month/day/year): $array = array( '1/10/2014', '1/11/2014', '1/12/2014', '1/13/2014', '1/14/2014' ); and I'd like to output the array with only dates of today or in the future. So if today is 1/12/2014 it would eliminate the 1/10/2014 and 1/11/2014. Here is what I have that isn't working: foreach ($array as $date) { $unixdate = strtotime($date); if ($unixdate < time()) { unset($array[$date]); } } print_r($array); I guess I'm not using unset

Removing expired dates from an array with PHP

大城市里の小女人 提交于 2020-11-29 10:33:48
问题 I have an array of dates formatted in 'm/d/Y' (month/day/year): $array = array( '1/10/2014', '1/11/2014', '1/12/2014', '1/13/2014', '1/14/2014' ); and I'd like to output the array with only dates of today or in the future. So if today is 1/12/2014 it would eliminate the 1/10/2014 and 1/11/2014. Here is what I have that isn't working: foreach ($array as $date) { $unixdate = strtotime($date); if ($unixdate < time()) { unset($array[$date]); } } print_r($array); I guess I'm not using unset

Java SQL date is off by 1 day

自作多情 提交于 2020-11-29 09:34:27
问题 I'm using a MySQL server which is located in the same timezone as me. Im trying to insert a java.util.Date into the database on a column of type DATE with the following code: SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT+2")); Date date = dateFormat.parse(map.value("date")); Where "date" is inserted. The problem is that the date is off by one day when looking in the database. Example: I inserted 2020-05-02, the database