Date/Time Formats

3.3 Date/Time Formats
3.3.1 Full Date

HTTP applications have historically allowed three different formats for the representation of date/time stamps:
      Sun, 06 Nov 1994 08:49:37 GMT  ; RFC 822, updated by RFC 1123
      Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
      Sun Nov  6 08:49:37 1994       ; ANSI C's asctime() format

The first format is preferred as an Internet standard and represents a fixed-length subset of that defined by RFC 1123 [8] (an update to RFC 822 [9]). The second format is in common use, but is based on the obsolete RFC 850 [12] date format and lacks a four-digit year. HTTP/1.1 clients and servers that parse the date value MUST accept all three formats (for compatibility with HTTP/1.0), though they MUST only generate the RFC 1123 format for representing HTTP-date values in header fields. See section 19.3 for further information.
      Note: Recipients of date values are encouraged to be robust in
      accepting date values that may have been sent by non-HTTP
      applications, as is sometimes the case when retrieving or posting
      messages via proxies/gateways to SMTP or NNTP.

All HTTP date/time stamps MUST be represented in Greenwich Mean Time (GMT), without exception. For the purposes of HTTP, GMT is exactly equal to UTC (Coordinated Universal Time). This is indicated in the first two formats by the inclusion of "GMT" as the three-letter abbreviation for time zone, and MUST be assumed when reading the asctime format. HTTP-date is case sensitive and MUST NOT include additional LWS beyond that specifically included as SP in the grammar.
       HTTP-date    = rfc1123-date | rfc850-date | asctime-date
       rfc1123-date = wkday "," SP date1 SP time SP "GMT"
       rfc850-date  = weekday "," SP date2 SP time SP "GMT"
       asctime-date = wkday SP date3 SP time SP 4DIGIT
       date1        = 2DIGIT SP month SP 4DIGIT
                      ; day month year (e.g., 02 Jun 1982)
       date2        = 2DIGIT "-" month "-" 2DIGIT
                      ; day-month-year (e.g., 02-Jun-82)
       date3        = month SP ( 2DIGIT | ( SP 1DIGIT ))
                      ; month day (e.g., Jun  2)
       time         = 2DIGIT ":" 2DIGIT ":" 2DIGIT
                      ; 00:00:00 - 23:59:59
       wkday        = "Mon" | "Tue" | "Wed"
                    | "Thu" | "Fri" | "Sat" | "Sun"
       weekday      = "Monday" | "Tuesday" | "Wednesday"
                    | "Thursday" | "Friday" | "Saturday" | "Sunday"
       month        = "Jan" | "Feb" | "Mar" | "Apr"
                    | "May" | "Jun" | "Jul" | "Aug"
                    | "Sep" | "Oct" | "Nov" | "Dec"
      Note: HTTP requirements for the date/time stamp format apply only
      to their usage within the protocol stream. Clients and servers are
      not required to use these formats for user presentation, request
      logging, etc.

Sure, I can help you with that. Here's the code for creating a digital clock in Java: ```java import java.awt.Color; import java.awt.Font; import java.awt.GridLayout; import java.text.SimpleDateFormat; import java.util.Calendar; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class DigitalClock extends JFrame { private JLabel hourLabel, minuteLabel, secondLabel, amPmLabel; public DigitalClock() { setTitle("Digital Clock"); setSize(300, 150); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(2, 2)); panel.setBackground(Color.BLACK); hourLabel = new JLabel("", JLabel.CENTER); hourLabel.setFont(new Font("Serif", Font.ITALIC, 36)); hourLabel.setForeground(Color.WHITE); panel.add(hourLabel); minuteLabel = new JLabel("", JLabel.CENTER); minuteLabel.setFont(new Font("Serif", Font.ITALIC, 36)); minuteLabel.setForeground(Color.WHITE); panel.add(minuteLabel); secondLabel = new JLabel("", JLabel.CENTER); secondLabel.setFont(new Font("Serif", Font.ITALIC, 36)); secondLabel.setForeground(Color.WHITE); panel.add(secondLabel); amPmLabel = new JLabel("", JLabel.CENTER); amPmLabel.setFont(new Font("Serif", Font.ITALIC, 20)); amPmLabel.setForeground(Color.WHITE); panel.add(amPmLabel); add(panel); setVisible(true); } public void updateTime() { Calendar calendar = Calendar.getInstance(); SimpleDateFormat timeFormat = new SimpleDateFormat("hh"); int hour = Integer.parseInt(timeFormat.format(calendar.getTime())); timeFormat = new SimpleDateFormat("mm"); int minute = Integer.parseInt(timeFormat.format(calendar.getTime())); timeFormat = new SimpleDateFormat("ss"); int second = Integer.parseInt(timeFormat.format(calendar.getTime())); timeFormat = new SimpleDateFormat("a"); String amPm = timeFormat.format(calendar.getTime()); hourLabel.setText(String.format("%02d", hour)); minuteLabel.setText(String.format("%02d", minute)); secondLabel.setText(String.format("%02d", second)); amPmLabel.setText(amPm); } public static void main(String[] args) { DigitalClock clock = new DigitalClock(); while (true) { clock.updateTime(); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } } ``` Here's how the code works: - The `DigitalClock` class extends `JFrame` and creates a window with a 2x2 grid with labels for the hours, minutes, seconds, and AM/PM. - The `updateTime` method gets the current time using `Calendar.getInstance()` and formats it using `SimpleDateFormat`. - The `main` method creates an instance of the `DigitalClock` class and runs a continuous loop that calls the `updateTime` method every second using `Thread.sleep(1000)`. I hope this helps you create your digital clock!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值