揮発性のメモ2

http://d.hatena.ne.jp/iww/

hoge

日付フォーマット出力

2012-10-03 16:33:58 みたいに出力する

perl

my ($S,$M,$H,$d,$m,$Y,$x) = localtime();
my $date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $Y+1900,$m+1,$d,$H,$M,$S );

print "$date\n";
use POSIX qw(strftime);
$date = strftime( "%Y-%m-%d %H:%M:%S", localtime );

print "$date\n";

php

<?
    $date = date("Y-m-d H:i:s");
//  $date = strftime("%Y-%m-%d %H:%M:%S");
//  $date = strftime("%F %T");

    echo "$date\n";
?>

C

#include <time.h>
main(){
    char date[20];
    time_t t=time(NULL);
    struct tm *tmp=localtime( &t );
    strftime( date, 20, "%Y-%m-%d %H:%M:%S", tmp );

    printf("%s\n",date);
}

bash

DATE=`date +"%Y-%m-%d %H:%M:%S"`

echo $DATE

mysql

SELECT DATE_FORMAT( NOW(), "%Y-%m-%d %H:%i:%s" );