I was tasked with comparing one date to another to see which one was greater. To compound the issue. They can be in different timezones. I tried to change the timezone of the DateTime object, but nothing happened. This is because Joda DateTime object are immutable. Doh. I needed a MutableDateTime object. I ended up with:
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("MM/dd/yyyy"); DateTime dateTime = dateTimeFormatter.parseDateTime(dateString); MutableDateTime mutableDateTime = dateTime.toMutableDateTime(); mutableDateTime.setZone(DateTimeZone.forID("America/Los_Angeles"));
Note that when a DateTime object is created, it takes the timezone from the system that created it. When you change the timezone, the offset value will change and the time is adjusted. If the offset changes by two hours, the time will change by two hours.
sheltonn January 10th, 2012
An example is you have a phone number, but it has mark-up such as ellipses or dashes.
String phoneNumber = "(555) 555-0000"; phoneNumber.replaceAll("[^\d]", "");
phoneNumber is now equal to “5555550000”.
sheltonn January 5th, 2012
Posted In: Java