I want to display column date in date format from moodle database:
View Code:
$table = new html_table();
$table->head = array('Date','Time', 'A' , 'B', 'C','D', 'E', 'F');
I'll be grateful for any reference or help on how to display date column in date format?
Use userdate() it will display the date in the users locale.
userdate($scheduledatet)
EDIT: You can also specify the date/time format in the users locale by using get_string()
$dateformat = get_string('strftimedateshort', 'langconfig');
userdate($scheduledatet);
These are the English formats in /lang/en/langconfig.php
$string['strftimedate'] = '%d %B %Y';
$string['strftimedatefullshort'] = '%d/%m/%y';
$string['strftimedateshort'] = '%d %B';
$string['strftimedatetime'] = '%d %B %Y, %I:%M %p';
$string['strftimedatetimeshort'] = '%d/%m/%y, %H:%M';
$string['strftimedaydate'] = '%A, %d %B %Y';
$string['strftimedaydatetime'] = '%A, %d %B %Y, %I:%M %p';
$string['strftimedayshort'] = '%A, %d %B';
$string['strftimedaytime'] = '%a, %H:%M';
$string['strftimemonthyear'] = '%B %Y';
$string['strftimerecent'] = '%d %b, %H:%M';
$string['strftimerecentfull'] = '%a, %d %b %Y, %I:%M %p';
$string['strftimetime'] = '%I:%M %p';
Related
I am using the
Log::Log4perl
module to capture log data. After midnight I am trying to roll the file over from count.log to count.log.1 in write mode, but I am not able to do so.
Below is the logfile info:
log4perl.rootLogger = INFO, myFILE
log4perl.appender.myFILE = Log::Dispatch::FileRotate
log4perl.appender.myFILE.filename = /user/Desktop/Records.log
log4perl.appender.myFILE.max = 4
log4perl.appender.myFILE.mode = write
log4perl.appender.myFILE.DatePattern = yyyy-MM-dd
log4perl.appender.myFILE.TZ = UTC
log4perl.appender.myFILE.layout = PatternLayout
#log4perl.appender.myFILE.layout.ConversionPattern = %d %m %n
#log4perl.appender.myFILE.layout.ConversionPattern = %m %n
log4perl.appender.myFILE.layout.ConversionPattern = [%d] [%F:%L] [%p %c] %m%n
I'm quite new to Python. I'm trying to convert a string object into a UNIX timestamp using strptime and mktime.
When I run my script in Python Shell, I get no errors - so the Date/Time format strptime gets as an argument must be OK. But when I try to implement the code into my full code (into a for loop) I get an error:
ValueError: time data 'Wed Mar 09 00:07:38 2016' does not match format '%a %b %d %H:%M:%S %Y'.
This is quite weird, knowing that the format is OK.
This is the script I tested in Python Shell:
import time
import datetime
datetimestring = 'Wed Mar 09 00:07:38 2016'
timestamp = time.mktime(time.strptime(datetimestring, '%a %b %d %H:%M:%S %Y'))
print timestamp
This is the code that doesn't work in my larger full code:
for row in rows:
report = str(getattr(row, 'answerTime'))
print report
timestamp = time.mktime(time.strptime(report, '%a %b %d %H:%M:%S %Y'))
print timestamp
For some reason I am having a lot of trouble parsing date strings using Time::Piece.
So this works:
my $t = Time::Piece->strptime( 'Sunday, November 4, 2012 10:25:15 PM -0000' , "%A, %B %d, %Y %I:%M:%S %p %z" );
print $t;
But this does not:
my $temp_time = Time::Piece->strptime('7/23/2014 5:24:22 PM', "%-m/%-d/%Y %l:%M:%S %p");
print $temp_time;
I have also used '%D %r' as the format string but that also does not work. Do any of you have insight as to why this might be? For reference , the hour is 1-12 (not 01-12) and the month is 1-12 (not 0-12).
Thanks!
Change
"%-m/%-d/%Y %l:%M:%S %p"
to
"%m/%d/%Y %l:%M:%S %p"
My platform is Linux. I want the printed date to be formatted as Apr 3, 2014, 5:28 PM when given input such as 2014-04-03T17:28:54.864Z.
My current Perl script.
#!/usr/bin/perl
use lib '/tmp/DateTime/Format';
use DateTime::Format::ISO8601;
my $date = "2014-04-03T17:28:54.864Z";
my $iso8601 = DateTime::Format::ISO8601 -> new;
my $dt = $iso8601->parse_datetime( $date );
print "Date before conversion *******-> \"$date\"\n";
my $s6 = $dt->strftime("%b %-d, %Y, %I:%M %p");
print "Date after conversion *******-> \"$s6\"\n";
It gives the output Apr %-d, 2014, 05:28 PM. When the day of the month or hour is a single digit, I do not want zero or space padding. I want the output as Apr 3, 2014, 5:28 PM when day and hour are each a single digit.
I see no %-d option listed in the valid strftime patterns.
You could use %e to get a leading space instead of a leading zero but, since you discount that, you can get the day independently, then change it and use that changed value within the format string, something like (untested, but you'll get the idea):
# Get day and remove leading zero.
my $dayofmonth = $dt->strftime("%d");
$dayofmonth =~ s/^0//;
# Construct format string from "hard-coded" day.
my $s6 = $dt->strftime("%b " . $dayofmonth . ", %Y, %I:%M %p");
Try this:
my $s6 = $dt->format_cldr('MMM d, Y, h:mm a');
It makes use of the module:
DateTime::Format::CLDR - Parse and format CLDR time patterns
Which you can find documented here.
Because there aren't any strftime patterns for days other than %d and %e, the easy solution is just to edit the result after the fact
$s6 =~ s/\s+/ /g;
This would change your script to the following:
use strict;
use warnings;
use DateTime::Format::ISO8601;
my $date = "2014-04-03T17:28:54.864Z";
my $iso8601 = DateTime::Format::ISO8601->new;
my $dt = $iso8601->parse_datetime( $date );
print qq{Date before conversion *******-> "$date"\n};
my $s6 = $dt->strftime("%b %e, %Y, %I:%M %p");
$s6 =~ s/\s+/ /g;
print qq{Date after conversion *******-> "$s6"\n};
I have a string of date and time of format:
Day, Month DAY_OF_MONTH, Year HH:MM:SS AM/PM GMT[+/-]hh:mm .
But I am unable to parse it. I have used this:
Time::Piece->strftime($string, "%A, %B %d, %Y %I:%M:%S %p %Z%z");
I have converted the string into the format : Day, Month DAY_OF_MONTH, Year HH:MM:SS AM/PM [+/-]hhmm . But still its not working for me with
Time::Piece->strftime($string, "%A, %B %d, %Y %I:%M:%S %p %z");
The string is getting parsed but the time zone is not considered in the Time::Piece object as tzoffset is 0000 and the HH of the date has the same value as that in the string. Please anyone help.
Eg: String to be parsed: Friday, July 25, 2008 12:15:57 PM GMT-0700
If Time::Piece doesn't work, try using Date::Parse.
And as oalders mentioned, do include an actual date string example in your question.
Perhaps the following will help:
use strict;
use warnings;
use Time::Piece;
my $string = 'Sunday, November 4, 2012 10:25:15 PM -0000';
my $t = Time::Piece->strptime( $string, "%A, %B %d, %Y %I:%M:%S %p %z" );
print $t;
Output:
Sun Nov 4 22:25:15 2012