Time and Date / Date Format

Scribbller 1 Tallied Votes 205 Views Share

Format a local time/date according to locale settings

LastMitch commented: Thanks for sharing +12
<?php
/*     December 2002 / January 2003
ISOWk  M   Tu  W   Thu F   Sa  Su
----- ----------------------------
51     16  17  18  19  20  21  22
52     23  24  25  26  27  28  29
1      30  31   1   2   3   4   5
2       6   7   8   9  10  11  12
3      13  14  15  16  17  18  19   */

// Outputs: 12/28/2002 - %V,%G,%Y = 52,2002,2002
print "12/28/2002 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("12/28/2002")) . "\n";

// Outputs: 12/30/2002 - %V,%G,%Y = 1,2003,2002
print "12/30/2002 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("12/30/2002")) . "\n";

// Outputs: 1/3/2003 - %V,%G,%Y = 1,2003,2003
print "1/3/2003 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/3/2003")) . "\n";

// Outputs: 1/10/2003 - %V,%G,%Y = 2,2003,2003
print "1/10/2003 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/10/2003")) . "\n";



/*     December 2004 / January 2005
ISOWk  M   Tu  W   Thu F   Sa  Su
----- ----------------------------
51     13  14  15  16  17  18  19
52     20  21  22  23  24  25  26
53     27  28  29  30  31   1   2
1       3   4   5   6   7   8   9
2      10  11  12  13  14  15  16   */

// Outputs: 12/23/2004 - %V,%G,%Y = 52,2004,2004
print "12/23/2004 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("12/23/2004")) . "\n";

// Outputs: 12/31/2004 - %V,%G,%Y = 53,2004,2004
print "12/31/2004 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("12/31/2004")) . "\n";

// Outputs: 1/2/2005 - %V,%G,%Y = 53,2004,2005
print "1/2/2005 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/2/2005")) . "\n";

// Outputs: 1/3/2005 - %V,%G,%Y = 1,2005,2005
print "1/3/2005 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/3/2005")) . "\n";

?>
Member Avatar for LastMitch
LastMitch

I just wanted to update this code snippet. The code snippet is from strftime function.

The function that is being used in this code snippet is called strftime and strtotime

Here is the update code:

<?php
/*       
December 2012 / January 2013   

ISOWk - Sun|Mon|Tue|Wed|Thu|Fri|Sat
-----   ---------------------------
 48                              1
 49      2   3   4   5   6   7   8
 50      9  10  11  12  13  14  15 
 51     16  17  18  19  20  21  22
 52     23  24  25  26  27  28  29
 53     30  31   1   2   3   4   5
  1      6   7   8   9  10  11  12 
  2     13  14  15  16  17  18  19   
  3     20  21  22  23  25  26  27
  4     28  29  30  31  */


// Outputs: 12/14/2012 - %V,%G,%Y = 50,2012,2012
echo "12/14/2012 - %V,%G,%Y = ".strftime("%V,%G,%Y",strtotime("12/14/2012")). "\n</br></br>";
// Outputs: 12/30/2012 - %V,%G,%Y = 53,2013,2012
echo "12/30/2012 - %V,%G,%Y = ".strftime("%V,%G,%Y",strtotime("12/30/2012")). "\n</br></br>";
// Outputs: 1/5/2013 - %V,%G,%Y = 1,2013,2013
echo "1/8/2013 - %V,%G,%Y = " .strftime("%V,%G,%Y",strtotime("1/8/2013")). "\n</br></br>";
// Outputs: 1/21/2013 - %V,%G,%Y = 3,2013,2013
echo "1/21/2013 - %V,%G,%Y = ".strftime("%V,%G,%Y",strtotime("1/21/2013")). "\n</br></br>";


/*       
December 2013 / January 2014   

ISOWk - Sun|Mon|Tue|Wed|Thu|Fri|Sat
-----   ---------------------------
 49      1   2   3   4   5   6   7                   
 50      8   9  10  11  12  13  14
 51     15  16  17  18  19  20  21 
 52     22  23  24  25  26  27  28
  1     29  30  31   1   2   3   4
  2      5   6   7   8   9  10  11
  3     12  13  14  15  16  17  18 
  4     19  20  21  22  23  24  25   
  5     26  27  28  29  30  31  */


// Outputs: 12/7/2013 - %V,%G,%Y = 49,2013,2013
echo "12/7/2013 - %V,%G,%Y = ".strftime("%V,%G,%Y",strtotime("12/7/2013")). "\n</br></br>";
// Outputs: 12/31/2013 - %V,%G,%Y = 52,2013,2013
echo "12/31/2013 - %V,%G,%Y = ".strftime("%V,%G,%Y",strtotime("12/31/2013")). "\n</br></br>";
// Outputs: 1/4/2014 - %V,%G,%Y = 1,2013,2014
echo "1/4/2014 - %V,%G,%Y = ".strftime("%V,%G,%Y",strtotime("1/4/2014")). "\n</br></br>";
// Outputs: 1/16/2014 - %V,%G,%Y = 3,2014,2014
echo "1/16/2014 - %V,%G,%Y = ".strftime("%V,%G,%Y",strtotime("1/16/2014")). "\n</br></br>";

?>

When I ran the code it came out like this (I'm not sure this looks corrected):

8ce9c57c49a3d823287ba13344902946

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.