format-time-string中%X和%x有什么区别?

时间:2012-07-21 14:56:11

标签: emacs elisp

以下功能中“%X”和“%x”之间有什么区别?!

(defvar insert-time-format "%X" 
"*Format for \\[insert-time] (c.f. 'format-time-string').")

-----------

(defvar insert-date-format "%x"
"*Format for \\[insert-date] (c.f. 'format-time-string').")

4 个答案:

答案 0 :(得分:1)

很明显,如果您看到插入时间格式的描述,您将看到:

%x是区域设置的“首选”日期格式。

%X是区域设置的“首选”时间格式。

答案 1 :(得分:1)

%x inserts the time.
%X inserts the date.

答案 2 :(得分:1)

您可能会根据变量名称insert-time-formatinsert-date-format对差异进行很好的猜测,但是之后您的第一个停靠点应该是format-time-string的帮助在这两个变量的帮助中引用的函数:

C-h f format-time-string RET

format-time-string is a built-in function in `C source code'.

(format-time-string FORMAT-STRING &optional TIME UNIVERSAL)

Use FORMAT-STRING to format the time TIME, or now if omitted.
TIME is specified as (HIGH LOW . IGNORED), as returned by
`current-time' or `file-attributes'.  The obsolete form (HIGH . LOW)
is also still accepted.
The third, optional, argument UNIVERSAL, if non-nil, means describe TIME
as Universal Time; nil means describe TIME in the local time zone.
The value is a copy of FORMAT-STRING, but with certain constructs replaced
by text that describes the specified date and time in TIME:

%Y is the year, %y within the century, %C the century.
%G is the year corresponding to the ISO week, %g within the century.
%m is the numeric month.
%b and %h are the locale's abbreviated month name, %B the full name.
%d is the day of the month, zero-padded, %e is blank-padded.
%u is the numeric day of week from 1 (Monday) to 7, %w from 0 (Sunday) to 6.
%a is the locale's abbreviated name of the day of week, %A the full name.
%U is the week number starting on Sunday, %W starting on Monday,
 %V according to ISO 8601.
%j is the day of the year.

%H is the hour on a 24-hour clock, %I is on a 12-hour clock, %k is like %H
 only blank-padded, %l is like %I blank-padded.
%p is the locale's equivalent of either AM or PM.
%M is the minute.
%S is the second.
%N is the nanosecond, %6N the microsecond, %3N the millisecond, etc.
%Z is the time zone name, %z is the numeric form.
%s is the number of seconds since 1970-01-01 00:00:00 +0000.

%c is the locale's date and time format.
%x is the locale's "preferred" date format.
%D is like "%m/%d/%y".

%R is like "%H:%M", %T is like "%H:%M:%S", %r is like "%I:%M:%S %p".
%X is the locale's "preferred" time format.

Finally, %n is a newline, %t is a tab, %% is a literal %.

Certain flags and modifiers are available with some format controls.
The flags are `_', `-', `^' and `#'.  For certain characters X,
%_X is like %X, but padded with blanks; %-X is like %X,
but without padding.  %^X is like %X, but with all textual
characters up-cased; %#X is like %X, but with letter-case of
all textual characters reversed.
%NX (where N stands for an integer) is like %X,
but takes up at least N (a number) positions.
The modifiers are `E' and `O'.  For certain characters X,
%EX is a locale's alternative version of %X;
%OX is like %X, but uses the locale's number symbols.

For example, to produce full ISO 8601 format, use "%Y-%m-%dT%T%z".

答案 3 :(得分:-1)

%x将输入格式化为十六进制。 %x和%X之间的区别在于字母是用大写字母书写的。

E.g。

  

%x,15将是f

     

%X,15将是F