Reply to topic  [ 8 posts ] 
Wanted: Date/Time Macro 
Author Message
User avatar

Joined: 2004-09-09 18:07:11
Posts: 333
Location: Utah
Hi all.

I'm wondering if someone would take pity on me and create a date/time macro for me. Specifically, I'd like a macro that would produce this with a single click:

Wednesday, June 17, 2007
9:51 PM

I know that there is a date/time macro built in, but I can't make heads or tails of Perl.

Thanks in advance.

Cheers


2007-07-17 19:52:33
Profile ICQ WWW
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Post 
Pity taken:

Code:
$fullDate = ''
$shortTime = ''

Begin Perl
   use POSIX qw(strftime);
   my $time = time;
   my @timestamp = localtime($time);
   
   my ($sec, $min, $hour, $day, $month, $year, $weekday) = localtime($time);
   $year += 1900;
   $monthName = strftime( '%B', @timestamp );
   $weekdayName = strftime( '%A', @timestamp );
   if( $hour > 12 ) {
      $hour -= 12;
   }
   elsif( 0 == $hour ) {
      $hour = 12; # for 12AM
   }
   $ampm = strftime( '%p', @timestamp );
   
   $fullDate = sprintf( '%s, %s %d, %04d', $weekdayName, $monthName, $day, $year );
   $shortTime = sprintf( '%d:%02d %s', $hour, $min, $ampm );
End

Type Text $fullDate
Type Newline
Type Text $shortTime


Last edited by martin on 2007-07-31 22:45:59, edited 1 time in total.



2007-07-18 00:07:13
Profile WWW
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Post 
I've added this macro (and a couple more date/time formats) to the macro repository.


2007-07-18 01:03:57
Profile WWW
User avatar

Joined: 2004-09-09 18:07:11
Posts: 333
Location: Utah
Post 
Thanks, Martin! Works like a charm! Exclamation point!


2007-07-18 07:04:32
Profile ICQ WWW
User avatar

Joined: 2004-10-26 07:10:40
Posts: 174
Location: Tucson, AZ
Post 
Good to see you back, midwinter. I've missed the banana.

_________________
MacBook Pro 15
2.66 Ghz Core i7
8GB RAM
10.8.3
NWP 2.0.4
iPad 3


2007-07-18 07:10:11
Profile
User avatar

Joined: 2004-09-09 18:07:11
Posts: 333
Location: Utah
Post 
scottwhitlock wrote:
Good to see you back, midwinter. I've missed the banana.


Thanks, Scott. It was a crazy semester followed by a broken foot followed by a research trip to Europe.

But I'm back and writing again, so my plan is to bury Martin in feature requests for the upcoming Nisus Writer Super-Pro. ;)


2007-07-18 07:26:31
Profile ICQ WWW
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Post 
midwinter found a bug in the macros I wrote. Basically all times in the 24th hour are printed as "00:MM AM" instead of "12:MM AM", eg: "00:55 AM" instead of "12:55 AM".

I've updated the macro files to fix this, so if you ever plan on writing in the midnight hour, it might be worth re-downloading them. Sorry everyone.


2007-07-31 22:44:54
Profile WWW
User avatar

Joined: 2003-09-30 21:33:58
Posts: 351
I haven't had a need for any of the macros, but I would just like to thank you for creating a page that has them on them

merci

please don't get your cape caught in the revolving door!!
http://s169.photobucket.com/albums/u202/librarymonkey27//monkey/niman.gif

_________________
I have never let my schooling interfere with my education/Mark Twain (1835-1910)


2007-08-01 18:24:33
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software