加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式 – SCORM 2004时间格式 – 正则表达式?

发布时间:2020-12-14 06:09:31 所属栏目:百科 来源:网络整理
导读:我正在为LMS构建SCORM 2004 javascript API,SCORM 2004的一个要求是传入它的时间间隔必须遵循以下格式.有谁知道这个正则表达式是什么?我试图围绕它,但无济于事.注意:P必须始终是第一个字符. P[yY][mM][dD][T[hH][nM][s[.s]S]] where: y: The number of yea
我正在为LMS构建SCORM 2004 javascript API,SCORM 2004的一个要求是传入它的时间间隔必须遵循以下格式.有谁知道这个正则表达式是什么?我试图围绕它,但无济于事.注意:P必须始终是第一个字符.

P[yY][mM][dD][T[hH][nM][s[.s]S]]
where:

  • y: The number of years (integer,>= 0,not restricted)
  • m: The number of months (integer,>=0,not restricted)
  • d: The number of days (integer,not restricted)
  • h: The number of hours (integer,not restricted)
  • n: The number of minutes (integer,not restricted)
  • s: The number of seconds or fraction of seconds (real or integer,not
    restricted). If fractions of a second are used,SCORM further restricts the string to
    a maximum of 2 digits (e.g.,34.45 – valid,34.45454545 – not valid).
  • The character literals designators P,Y,M,D,T,H,M and S shall appear if the
    corresponding non-zero value is present.
  • Zero-padding of the values shall be supported. Zero-padding does not change the
    integer value of the number being represented by a set of characters. For
    example,PT05H is equivalent to PT5H and PT000005H.

Example –

  • P1Y3M2DT3H indicates a period of time of 1 year,3 months,2 days and 3
    hours
  • PT3H5M indicates a period of time of 3 hours and 5 minutes

任何帮助将不胜感激.

谢谢!

更新:

我添加了一些必须保留的额外标准 –

  • The designator P shall be present
  • If the value of years,months,days,hours,minutes or seconds is
    zero,the value and corresponding
    character literal designation may be
    omitted,but at least one character
    literal designator and value shall be
    present in addition to the designator
    P
  • The designator T shall be omitted if all of the time components (hours,
    minutes and seconds) are not used. A
    zero value may be used with any of the
    time components (e.g.,PT0S)

解决方法

这是我使用的正则表达式;

^P(?=w*d)(?:d+Y|Y)?(?:d+M|M)?(?:d+D|D)?(?:T(?:d+H|H)?(?:d+M|M)?(?:d+(?:-.d{1,2})?S|S)?)?$

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读