We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › date to string / split question
Page Index Toggle Pages: 1
date to string / split question (Read 1498 times)
date to string / split question
Aug 23rd, 2009, 7:53am
 
Hi, i am using a library that seems to return a "Date" variable. Is this pure Java? couldnt find anything about it on the processing Site.  
How can in convert this into a String?

Thank you for your help

edit: have antoher simple question maybe i can just add it here.
I wanna seperate and split different Strings with a char, i always use ; or , but is there a char i can be sure of that it will not be part of my string to avoid any problems?
Re: date to string / split question
Reply #1 - Aug 23rd, 2009, 9:03am
 
Quote:
Hi, i am using a library that seems to return a "Date" variable. Is this pure Java? couldnt find anything about it on the processing Site.  
How can in convert this into a String?


The default toString() of a java.util.Date class, assuming that it is a java.util.Date you're talking about (there are other Date classes!), looks like this: 'Sun Aug 23 17:55:34 CEST 2009' in my Locale. You can "re-format" the String representation of a Date class by using the SimpleDateFormat class. Here's a demo:

Code:
Date now = new Date();
println("now = "+now);
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyy");
println("now formatted to 'dd/MM/yyy' = "+sdf.format(now));


Quote:
edit: have antoher simple question maybe i can just add it here.
I wanna seperate and split different Strings with a char, i always use ; or , but is there a char i can be sure of that it will not be part of my string to avoid any problems?


No, if the delimiter can be used as a separator in your String, it can also be used in the String itself. I'd use a 3rd party CSV parser if there's a risk of delimiter chars getting caught up in the String values.

Good luck!
Re: date to string / split question
Reply #2 - Aug 23rd, 2009, 9:06am
 
Can be Date or Date...
Supposing it is the first one, you can use DateFormat to get precise control on the look of the string. Otherwise, dateObject.toString() might be enough for you needs...

Separators: you can never be sure, but using a control char is somehow safer, a common one is Tab (TSV).
Page Index Toggle Pages: 1