Or you do a simple custom formatter with Bogdans trick:

public class SimpleTimestampFormat extends java.text.SimpleDateFormat {

  public TOTimestampFormat() { super(); }

  public TOTimestampFormat(String pattern) { super(pattern); }

  

  public TOTimestampFormat(String pattern, Locale locale) { super(pattern, locale); }

  

  public TOTimestampFormat(String pattern, DateFormatSymbols formatSymbols) { super(pattern, formatSymbols); }

  

  public Object parseObject(String source, ParsePosition pos) { return new NSTimestamp((Date)super.parseObject(source, pos)); }

  

  public NSTimestamp parse(String source) throws ParseException { return new NSTimestamp(super.parse(source)); }
}

Here is a more elaborate one, with formatting symbols from simpleDateFormat:

Attachment: TOTimestampFormat.java
Description: Binary data


Works great in components!

/Fredrik


2 dec 2014 kl. 13:36 skrev Chuck Hill <[email protected]>:

NSTimestampFormatter. Ignore the deprecation.

Chuck Hill
Gevity Consulting Inc.

Sent from my mobile device.

On Dec 2, 2014, at 5:49 PM, Thomas LATTER <[email protected]> wrote:

Hi, what is the simplest way these days to convert a string or Date to NSTimestamp ?

I can't seem to use SimpleDateFormat because java.util.Date cannot be cast to com.webobjects.foundation.NSTimestamp ...
String stringDate = "01/01/2014";
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
NSTimestamp deplDate = (NSTimestamp) dateFormat.parse(stringDate);

Thanks in advance,
tom
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/chill%40gevityinc.com

This email sent to [email protected]

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/frelin%40timeoff.se

This email sent to [email protected]

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to