simpledateformat

Comparing time is incorrect when picking 12:00

人盡茶涼 提交于 2019-12-17 03:21:38
问题 I am creating a booking system and I don't want to allow users to book with starting time 11:00 and end time 09:00 (past)(I am using 24hour clock). I have two combo boxes filled with Strings that act as start and end time (09:00,10:00,11:00,12:00,13:00....) I have this code: String start = (String) startTime.getSelectedItem(); String end = (String) endTime.getSelectedItem(); try { if(new SimpleDateFormat("hh:mm").parse(start).before(new SimpleDateFormat("hh:mm").parse(end))){ System.out

Changing String date format

▼魔方 西西 提交于 2019-12-17 02:32:02
问题 my current date format is : 08/11/2008 00:00 I need to convert this output to 2008/11/08 00:00 However, using the SimpleDateFormat as researched it is unable to do so and give me a totally different output, here are my codes as Follows : SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy/MM/dd HH:mm") Date starting= simpleDateFormat2.parse(startTime); System.out.println("" + simpleDateFormat2.format(starting) + " real date " + startTime); i do know that i am parsing in the right

Unparseable date error on Java

那年仲夏 提交于 2019-12-16 18:04:11
问题 import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Map; import java.util.Scanner; import java.util.TreeMap; public class L10C { public static void main(String[] args) throws Exception { File f = new File("src/Birthdates.txt"); Scanner input = new Scanner(f); //-------------------------------------------------Read File & Create N2D Map Map<String, Date> n2d = new TreeMap<String, Date>(); int n = input.nextInt(); for (int r = 0; r < n; r++) { //

Error to parse date: “Unparseable date: ”Jue 28-05-2016 22:30“ (at offset 0)”

旧城冷巷雨未停 提交于 2019-12-14 04:21:19
问题 i'm new in Android and I want to parse a string with a date to convert it to a calendar object and then send it to the Android Calendar. My string value is Jue 28-05-2015 22:30 (Jue for Jueves, thursday in spanish) and my code looks like this: fechaevento = Calendar.getInstance(); beginTime ="Jue 28-05-2016 22:30" final SimpleDateFormat sdf = new SimpleDateFormat("EEE dd-MM-yyyy kk:mm"); btnCalendar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try {

Java Parse Date w/ SimpleDateFormat

只谈情不闲聊 提交于 2019-12-14 04:01:06
问题 I'm sure this is a simple one! I've got this String String date = "Wed, 2 Jan 2013 12:17:15 +0000 (GMT)" which I want to parse to a Date to be able to set an JavaMail's sent date. Here's my full code String dateString = "Wed, 2 Jan 2013 12:17:15 +0000 (GMT)"; SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z"); Date date = sdf.parse(dateString); System.out.println("Date: " + date.toString()); email.setSentDate(oDate); // Assume email is initialised correctly Expected

Java Simple Date Format [duplicate]

北战南征 提交于 2019-12-14 03:36:20
问题 This question already has answers here : Illegal pattern character 'Y' on Ubuntu (2 answers) Closed 6 years ago . I am trying to format text into a date. Here is what I have: String pattern = "yyyy.MM.dd"; SimpleDateFormat sdf = new SimpleDateFormat(pattern); Date d=sdf.parse("12.1.5"); I get: java.lang.IllegalArgumentException: Illegal pattern character 'Y' at this point. I have also tried using a ParsePosition as well as "2012.01.05". Same error. How can I parse this string into a date? Any

How to set Z as timezone in SimpleDateFormat

泪湿孤枕 提交于 2019-12-14 03:35:29
问题 Code sample: SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); System.out.println(dateFormat.getTimeZone()); System.out.println(dateFormat.parse(time)); // dateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Kolkata")); I don't want to use the commented section. Zone should be set based on IST that I am giving in the input string: String time ="2018-04-06 16:13:00 IST"; Current machine zone is: America/New_York . How should I get zone changes to IST based on z?

Changing time zone with Calendar object from EEST to HST changes the time-of-day unexpectedly

无人久伴 提交于 2019-12-14 03:25:02
问题 I have some TimeStamp and I have date format "EEEE, MMM dd, yyyy hh:mm a zzz" . But I don't know how I can show this timestamp with timezone. When I trying to show it I get wrong DateTime or wrong timezone example1: Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date(device.getUpdatedDate().getTime())); // here is 2018-07-09 20:02:26.506000 SimpleDateFormat sdf = new SimpleDateFormat(EMAIL_DATE_FORMAT); sdf.format(calendar.getTime()); // i have wrong timezone and i get

Java SimpleDateFormat returning wrong value in Date object

主宰稳场 提交于 2019-12-14 03:16:49
问题 I'm trying to parse a string to get a Date object, but it's always returning Sun. December 30, 2012 for the date. Does anyone have any ideas on what I'm doing wrong? I was using the same code using strings in YYYY-MM-dd format and it worked just fine, so I'm not sure why switching to this format is causing issues. public static Date getDateObjFromStr(String dateStr) { DateFormat formatter = new SimpleDateFormat("MM/dd/YYYY"); Date dateObj; try { dateObj = formatter.parse(dateStr); return

Unparsable Date with colon-separated timezone

南楼画角 提交于 2019-12-14 02:33:30
问题 I'm trying to parse this String 2014-04-04T14:28:38+02:00 It should be ISO 8601 format. But i can't parse it to a correct Date. I've tried the following: String example = "2014-04-04T14:28:38+02:00" public final static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz") Date tempDate = df.parse(example) But I get always the message "unparseable Date" I can not change the example because it's a value from a webservice. Could it be there is a probleme with "+02:00" instead of "