• Post Reply Bookmark Topic Watch Topic
  • New Topic

Convert AWK script  RSS feed

 
Dan Grindstaff
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to convert the following AWK script to JAVA:

tdate = strftime("%Y%m%d%M%S",systime())

The script changes the current date and time to a string YYYYmmddMMSS (YEAR, Month, Day, Minnutes, Seconds)

Here is what I have so far:

import java.util.Calendar;



/**
* @author A144
*
*/
public class AWKdateUtil {

/**
* @param args
*/

public static String getTimeString(String format) throws Exception {
try {
if (format = "%Y%m%d%M%S") {
To_String(Calendar.YEAR(this.)));
}
}


public static void main(String[] args) {
// TODO Auto-generated method stub

String tdate = getTimeString("%Y%m%d%M%S");

}


}

Can anyone give me an idea about how to proceed?

thanks,
Dan
 
Paul Clapham
Sheriff
Posts: 22823
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Throw away that code and rewrite:
 
Dan Grindstaff
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for the reply. I have discovered that now I must write the method to strip off characters and interpret them. For instance, I have to account for any length string that might come in. The only sure thing I have is that the character to assess will be preceeded by '%'. I am really stuck with this one and would appreciate any help. An example would be: %M%Y%s%m%q comes in. I have to advance through the string by using the % as a marker and assessing the character afterwards as legitimate or not, then assign a value and finally concatenate the values together as a datetime. In this example, 'q' would be rejected. I was thinking of using Substring with this but not sure how to implement it. Any ideas are most welcome. Thanks.
[ March 28, 2007: Message edited by: Dan Grindstaff ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!