Ask Your Question

Revision history [back]

My experiments show the following:

  1. StarBasic Format() run-time function accepts all the number format codes mentioned here.
  2. You may use the [$-langid] syntax to use the desired locale in the [b]Format()[b] output, like:

    sText = Format(Now(),"[$-41e]D MMMM YYYY") ' Thai
    
  3. The LangIDs might be taken from this page.

This, however, needs the parts from @Lupp's answer to get the current char locale to create complete solution.

My experiments show the following:

  1. StarBasic Format() run-time function accepts all the number format codes mentioned here.
  2. You may use the [$-langid] syntax to use the desired locale in the [b]Format()[b] [b]Format()[/b] output, like:

    sText = Format(Now(),"[$-41e]D MMMM YYYY") ' Thai
    
  3. The LangIDs might be taken from this page.

This, however, needs the parts from @Lupp's answer to get the current char locale to create complete solution.

My experiments show the following:

  1. StarBasic Format() run-time function accepts all the number format codes mentioned here.
  2. You may use the [$-langid] syntax to use the desired locale in the [b]Format()[/b] Format() output, like:

    sText = Format(Now(),"[$-41e]D MMMM YYYY") ' Thai
    
  3. The LangIDs might be taken from this page.

This, however, needs the parts from @Lupp's answer to get the current char locale to create complete solution.

My experiments show the following:

  1. StarBasic Format() run-time function accepts all the number format codes mentioned here.
  2. You may use the [$-langid] [$-langid] syntax to use the desired locale in the Format() output, like:

    sText = Format(Now(),"[$-41e]D MMMM YYYY") ' Thai
    
  3. The LangIDs might be taken from this page.

This, however, needs the parts from @Lupp's answer to get the current char locale to create complete solution.

My experiments show the following:

  1. StarBasic Format() run-time function accepts all the number format codes mentioned here.
  2. You may use the [$-langid] syntax to use the desired locale in the Format() output, like:

    sText = Format(Now(),"[$-41e]D MMMM YYYY") ' Thai
    
  3. The LangIDs might be taken from this page.

This, however, needs the parts from @Lupp's answer to get the current char locale to create complete solution.

EDIT 2017-10-31

To go with field creation, you may use this code:

sub Insert_Date_Auto
    dim document   as object
    dim dispatcher as object
    dim oLocale    as object
    oLocale = ThisComponent.CurrentController.GetViewCursor.CharLocale

    dim nFmtId as Long
    nFmtId = ThisComponent.NumberFormats.queryKey("DD MMMM YYYY", oLocale, True)
    if nFmtId = -1 then
       nFmtId = ThisComponent.NumberFormats.AddNew("DD MMMM YYYY", oLocale)
    end if

    dim args1(3) as new com.sun.star.beans.PropertyValue
    args1(0).Name = "Type"
    args1(0).Value = 0 ' date
    args1(1).Name = "SubType"
    args1(1).Value = 0 ' fixed
    args1(2).Name = "Name"
    args1(2).Value = "" ' to avoid opening dialog
    args1(3).Name = "Format"
    args1(3).Value = nFmtId

    document   = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
    dispatcher.executeDispatch(document, ".uno:InsertField", "", 0, args1())
end sub

My experiments show the following:

  1. StarBasic Format() run-time function accepts all the number format codes mentioned here.
  2. You may use the [$-langid] syntax to use the desired locale in the Format() output, like:

    sText = Format(Now(),"[$-41e]D MMMM YYYY") ' Thai
    
  3. The LangIDs might be taken from this page.

This, however, needs the parts from @Lupp's answer to get the current char locale to create complete solution.

EDIT 2017-10-31

To go with field creation, you may use this code:

sub Insert_Date_Auto
    dim document   as object
    dim dispatcher as object
    dim oLocale    as object
    oLocale = ThisComponent.CurrentController.GetViewCursor.CharLocale

    dim nFmtId as Long
    nFmtId = ThisComponent.NumberFormats.queryKey("DD MMMM YYYY", oLocale, True)
False)
    if nFmtId = -1 then
       nFmtId = ThisComponent.NumberFormats.AddNew("DD ThisComponent.NumberFormats.addNew("DD MMMM YYYY", oLocale)
    end if

    dim args1(3) as new com.sun.star.beans.PropertyValue
    args1(0).Name = "Type"
    args1(0).Value = 0 ' date
    args1(1).Name = "SubType"
    args1(1).Value = 0 ' fixed
    args1(2).Name = "Name"
    args1(2).Value = "" ' to avoid opening dialog
    args1(3).Name = "Format"
    args1(3).Value = nFmtId

    document   = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
    dispatcher.executeDispatch(document, ".uno:InsertField", "", 0, args1())
end sub