Mercurial > hg > ltpda
comparison m-toolbox/classes/@time/strftime.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % STRFTIME Formats a time expressed as msec since the epoch into a string | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: STRFTIME(MSEC, FRMT, TIMEZONE) Formats the time MSEC, expressed | |
5 % as milliseconds since the unix epoch, 1970-01-01 00:00:00.000 UTC, into a | |
6 % string, accordingly to the format descrption FRMT and the timezone TIMEZONE. | |
7 % | |
8 % The FRMT format description can be a format number or a free form date format | |
9 % string, as accepted by the datestr() MATLAB function. The FRMT and TIMEZONE | |
10 % arguments are optional, if they are not specified or empty, the ones stored in | |
11 % the toolbox user preferences are used. | |
12 % | |
13 % EXAMPLES: | |
14 % | |
15 % >> msec = time.now(); | |
16 % >> str = time.strftime(msec); | |
17 % >> str = time.strftime(msec, 'yyyy-mm-dd HH:MM:SS.FFF z'); | |
18 % >> str = time.strftime(msec, 'yyyy-mm-dd HH:MM:SS.FFF z', 'UTC'); | |
19 % | |
20 % SEE ALSO: datestr | |
21 % | |
22 % VERSION: $Id: strftime.m,v 1.2 2011/03/24 14:49:37 mauro Exp $ | |
23 % | |
24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
25 | |
26 function str = strftime(msec, frmt, timezone) | |
27 | |
28 % check input arguments | |
29 error(nargchk(1, 3, nargin, 'struct')); | |
30 | |
31 % second and third arguments are optional | |
32 if nargin < 3 | |
33 timezone = ''; | |
34 end | |
35 if nargin < 2 | |
36 frmt = ''; | |
37 end | |
38 | |
39 % In the case of NaN, just set the output to 'NaN' | |
40 if isnan(msec) | |
41 str = 'NaN'; | |
42 return | |
43 end | |
44 | |
45 % check timezone | |
46 if isempty(timezone) | |
47 timezone = time.timezone; | |
48 end | |
49 % convert string timezone into java object | |
50 if ischar(timezone) | |
51 timezone = java.util.TimeZone.getTimeZone(timezone); | |
52 end | |
53 | |
54 % check frmt | |
55 if isempty(frmt) | |
56 frmt = time.timeformat; | |
57 end | |
58 % convert matlab time formatting specification string into a java one | |
59 frmt = time.matfrmt2javafrmt(frmt); | |
60 | |
61 % format | |
62 tformat = java.text.SimpleDateFormat(frmt); | |
63 tformat.setTimeZone(timezone); | |
64 str = char(tformat.format(msec)); | |
65 | |
66 end | |
67 |