Re: Getting time components of date
Re: Getting time components of date
- Subject: Re: Getting time components of date
- From: Graff <email@hidden>
- Date: Tue, 23 Dec 2003 03:23:02 -0500
Well if we are talking speed, you probably won't get faster than this
unless you like to code in machine code:
-------------
#include <stdio.h>
#include <time.h>
#define MAX_SIZE 32
#define FORMAT_STRING "%Y-%m-%d %H:%M:%S\n"
int main (int argc, const char * argv[])
{
time_t *currTime;
struct tm *currLocalTime;
char outputString[MAX_SIZE];
time(currTime);
currLocalTime = localtime(currTime);
if (currLocalTime != NULL)
{
strftime(outputString, MAX_SIZE - 1, FORMAT_STRING, currLocalTime);
}
printf("%s", outputString);
return 0;
}
-------------
Put it into a text editor, save it on your desktop as a plain text file
with unix line endings and the name "timestring.c". Go into the
terminal and type:
cc ~/Desktop/timestring.c -o ~/Desktop/timestring
Boom, your very own command-line tool. Run it in AppleScript like this:
set theTime to do shell script "~/Desktop/timestring"
Don't mind me, I'm feeling a little cheeky. ;-)
- Ken
On Dec 23, 2003, at 12:02 AM, Christopher Stone wrote:
At 7:59 AM -0500 12/22/03, Chris Garaffa wrote:
While working to convert an AppleScript date to a MySQL DATETIME date
(yyyy-mm-dd hh:mm:ss) I ran into a small problem. While AppleScript
supports things like:
______________________________________________________________________
Here's Arthur Knapp's handler. On my system it creates the requisite
date string in ~ 0.0024 seconds.
As opposed to ~ 0.01 seconds for the shell script.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.