转载至http://www.ilovematlab.cn/thread-648-1-1.html
time.m
function varargout = time(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @time_OpeningFcn, ...
'gui_OutputFcn', @time_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function time_OpeningFcn(hObject, eventdata, handles, varargin)
handles.timer = timer('Period',1,'ExecutionMode','FixedRate', 'TimerFcn',{@timercallback,handles});
handles.output = hObject;
guidata(hObject, handles);
function timercallback(obj, event, handles)
set(handles.edit1, 'String', datestr(now, 'HH:MM:SS'));
function varargout = time_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function edit1_Callback(hObject, eventdata, handles)
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function pushbutton1_Callback(hObject, eventdata, handles)
start(handles.timer);
function pushbutton2_Callback(hObject, eventdata, handles)