Formatting a Date based on the user's Locale

I'm having some trouble formatting a date based on the user's locale. I'm aware you can do something like this:
   public static String getAsString( Object dateObject, Locale locale ) {
      DateFormat dateFormat = DateFormat.getDateInstance( DateFormat.MEDIUM, locale );
      return dateFormat.format( dateObject );
However, this is returning something like Jan 21, 2009. I need 01/21/2009. Of course, if this was the UK locale it'd have to be 21/01/2009. Any help would be appreciated.

another issue I'm running into is that when I'm logged in as a users' locale which uses '-' instead of '/' (i.e. 21-01-2009), I get a parse error. Can anyone provide any input? Thanks.
    * Parse a Date
    * @param dateString
    * @param locale
    * @return parsed Date
   public static Object parseDate( String dateString, Locale locale ) {
      DateFormat dateFormat = DateFormat.getDateInstance( DateFormat.SHORT, locale );
      try {
         return dateFormat.parse( dateString );
      catch( Exception exception ) {
         throw new ExceptionUtl( UtlMessageHelper.getMessage( UtlMessageConstants.ERROR_FailedParseDateFromString, dateString ), exception );
    * Format the given value into a DateFormat
    * @param dateObject
    *           Object value to be formatted
    * @param locale
    *           Locale format to use
    * @return dateObject in SimpleDateFormat
   public static String formatDate( Object dateObject, Locale locale ) {
      DateFormat dateFormat = DateFormat.getDateInstance( DateFormat.SHORT, locale );
      if( dateFormat instanceof SimpleDateFormat ) {
         SimpleDateFormat simpleDateFormat = ( SimpleDateFormat )dateFormat;
         String pattern = simpleDateFormat.toPattern();
         if( !pattern.contains( "yyyy" ) ) {
            pattern = pattern.replace( "yy", "yyyy" );
         if( !pattern.contains( "dd" ) ) {
            pattern = pattern.replace( "d", "dd" );
         if( !pattern.contains( "MM" ) ) {
            pattern = pattern.replace( "M", "MM" );
         simpleDateFormat = new SimpleDateFormat( pattern );
         return simpleDateFormat.format( dateObject );
      return null;
   }

Similar Messages

  • Restricting the population of data based on the user & his organization

    Hi,
    I want to have following requirement fulfilled
    Suppose there are 3 company codes under one company.
    I do not want a user of one company to see the data of another company code or plant.
    For example:
    Selection of PO from drop down list or selection of vendor from drop down list in case user is searching for them in any of the transaction.
    He should see only the vendors for he is responsible or he should see only those PO numbers which are relevant for his organizational unit.
    He should not be able to see other data.
    There are similar kind of restrictions required .
    How this can be achieved.How can we restrict system in populating this ?
    Thanks in advance
    manOO

    Authorizations can be restricted by company code and purchasing organizations. Standard SAP transactions and reports have checks that ensure that the user sees only those records for which he is authorized.
    Lakshman

  • Data view web part to display the most frequently accessed pages based on the user that is logged in

    I am working on a project in which I would like to display the top 5 most accessed pieces of content as links, based on the user that is logged in. Our MOSS 2007 implementation has subsites for all regions that we do business in, as an example North, South, East, and West. When a user visits the North region homepage, I would like a web part to display:
    Hello, <username>, here is a listing of your most accessed content:
    Link to One
    Link to Two
    Link to Three
    Link to Four
    Link to Five
    So each user would get a customized list based on their content access. We are not using my sites, but these would not work as we want the list to display on the home page of the region site.
    I am thinking that a data view may work here, but I am not sure. Any help is greatly appreciated.

    If you are running MOSS you may want to take a look at the Relevant Documents web part too.
    http://office.microsoft.com/en-us/sharepointserver/HA102410251033.aspx
    The Relevant Documents Web Part helps you create a personalized view of the documents that you create, check out, and change. In a large Document Center, the Web Part can save you time and effort by making files easier to find and use. The following figure shows the Web Part:

  • Notification: Set priority and dates, based on the reference object

    Hello,
    I'm searching for an idea/solution, to set the priority of a notification automatically, depending on the entered reference object (F/L or equi).
    I.e. I want to classify the F/Ls and equis with a priority (e.g. via the classification, or F/L / equi master data). When the user creates a notification, and enters a F/L or equi, the priority should be selected from the object and set automatically.
    Thanks for your answers!
    Best regards
    Stephan

    Hello Pete,
    thank you for your answer. Unfortunatelly both user-exits seem not to work for my problem.
    QQMA0025: Default values when adding a notification
    Priority and dates can be modified, but in this step you don't have the functional location. I thought, I can send a popup in this user-exit, to ask for the functional location, but the functional location is deleted in a later step (before the 1st display of the notification header), i.e. the user has to enter it again.
    QQMA0018: Deadline setting based on entered priority
    Here you can only modify the dates / times, but not the priority.
    Another show stopper is, that the exits will only be processed once, i.e. in both cases, a change of the functional location doesn't adjust the dates/times.
    It seems, that exit "Before saving the notification" (as far as I remember QQMA0014) could be a solution.
    I see 2 problems ->
    1. the user enters the F/L or equi and nothing happens to the priority / dates -> sending a popup in the saving process to inform the user about the changes, could be a solution.
    2. What to do, when the user has already maintained priority and/or dates/times?
    I will have a look, if there are enhancement spots in the notification program. Perhaps this can help me (or better - my boss ).
    Best regards
    Stephan

  • Test-OutlookConnectivity fails with '[Microsoft.Exchange.Data.Storage.WrongServerException]: The user and the mailbox are in different Active Directory sites'.

    I have a two site DAG, and the command is running from the alternate site where the databases are not currently being hosted. The following command...
    Test-OutlookConnectivity -Protocol:TCP -TrustAnySSLCert:$true -MonitoringContext:$true
    ...errors with the following output:
    An error occurred while trying to access mailbox CurrentlyHostingMBServerName.InternalDomainName, on behalf of user InternalDomainName\extest_bb13200232474
     Additional information:
     [Microsoft.Exchange.Data.Storage.WrongServerException]: The user and the mailbox are in different Active Directory sit
    es..
        + CategoryInfo          : OperationStopped: (Microsoft.Excha...onnectivityTask:TestOutlookConnectivityTask) [Test-
       OutlookConnectivity], CasHealthStorageErrorException
        + FullyQualifiedErrorId : F2F8AC0D,Microsoft.Exchange.Monitoring.TestOutlookConnectivityTask
    I thought this command would work based on the 'AllowCrossSiteRpcClientAccess: True' option on the DAG.  The command works well if run a CAS server in the active DB site.

    Hi,
    Exchange 2013 users use Outlook Anywhere to connect to CAS server. You may run the RCA to test the connectivity:
    https://www.testexchangeconnectivity.com/
    Thanks,
    Simon Wu
    TechNet Community Support

  • Based on the user response need to calculate measures in universe

    Hello Folks,
    I have report where user prompts for the single day (Ex: OCT 1 2014).All calculations should be at universe layer.
    1.Based on the user response I need to create a report for previous months .
    2. PYTD and YTD measures based on user prompt from universe. [PYTD - JAN 1 2013-OCT 1 2013, YTD - Jan 1 2014- OCT 1 2014].
    Example Date Set :
    DIM 1                    SEP13...............................................................OCT 14      PYTD   YTD
    Florida  state        M1.Single value need to give previous 13 months data    M3        M4
                 federal    M2..Single value need to give previous 13 months data   M5       M6.
    Arizona  state        M1.Single value need to give previous 13 months data    M3        M4
                 federal    M2..Single value need to give previous 13 months data   M5       M6.
    M1...M6 are the measures need to come from universe based on the user prompt.
    M1,M2 Need to give previous 13 months based on user response.
    M3,M5 [PYTD - JAN 1 2013-OCT 1 2013]
    M4,M6 YTD - Jan 1 2014- OCT 1 2014].
    Thanks for your help in advance.

    Hello Folks,
    I have report where user prompts for the single day (Ex: OCT 1 2014).All calculations should be at universe layer.
    1.Based on the user response I need to create a report for previous months .
    2. PYTD and YTD measures based on user prompt from universe. [PYTD - JAN 1 2013-OCT 1 2013, YTD - Jan 1 2014- OCT 1 2014].
    Example Date Set :
    DIM 1                    SEP13...............................................................OCT 14      PYTD   YTD
    Florida  state        M1.Single value need to give previous 13 months data    M3        M4
                 federal    M2..Single value need to give previous 13 months data   M5       M6.
    Arizona  state        M1.Single value need to give previous 13 months data    M3        M4
                 federal    M2..Single value need to give previous 13 months data   M5       M6.
    M1...M6 are the measures need to come from universe based on the user prompt.
    M1,M2 Need to give previous 13 months based on user response.
    M3,M5 [PYTD - JAN 1 2013-OCT 1 2013]
    M4,M6 YTD - Jan 1 2014- OCT 1 2014].
    Thanks for your help in advance.

  • Restrict Org details based on the User in Business partner creation..

    Hi Gurus,.
    I have to assign Sales Org , DIV, Distribution Channel to the Business Partner in Sales Area data.  When I try system shows entire Org structure. But I want the Org structure should be displayed based on the user log on. Assume that, I am assigned to Shangai and creating Business partner for Shangai, the system should not show Beijing or other Org Unit since I belong to Shangai.  How to address this scenario thro standard customization?
    Is it common problem in CRM Webui(6.0 and 7.0).
    My Org Structure:
    Global
      China
         Shangai
         Beijing
       Nanjing.
    Thanks in Advance....

    Hi Denis,
       Thanks for your reply. I believe Org determination rule is applicable for Transaction types not for Account Creation. I want to get Sales area data based on login user. It shows complete Sales Area(Sales Org IDDistribution ChannelDivision) when I create an Account.. Assume that you are an employee and assigned to Newyork, when you create New Customer in Newyork, system should not show Boston, Washington Sales areas...Please throw some light on this...
    Thanks in Advance.,

  • Blazeds + Spring security: fetch data based on current user

    Hi,
    I'm currently learning flex by trying to build an application with
    flex, blazeds and Spring. My application lets users log on using
    spring security (which I will probably combine with
    AcegiLogonCommand). I would like my assemblers to return different
    data based on which user is currently logged on (for instance to show
    that specific user's to-do list). To do this, I added a userId
    property to my spring security principals (by subclassing
    org.springframework.security.userdetails.User)
    and added user_id columns to user-specific data in the database. Now
    I would like to know how I can get the currently logged on user in my
    assembler so I can use its userId to fetch the user's data.
    Is the assembler the right place to decide which data to send to my
    flex application? If so, can anyone tell me how to determine which
    user is currently logged on in my assembler? If not, what would be the
    recommended way of dealing with user-specific data in my database in
    combination with blazeds?
    The only examples I have been able to find on the Internet so far only
    use different roles to determine what a user is or is not allowed to
    do, I have yet to find any examples where users store and retrieve
    user-specific data.
    Kind regards,
    Jeroen

    Hi,
    There is a field “Target Audience” in list whenever “Target Audience” is enable in “List Settings”, it accepts the name of a SharePoint group.
    For your requirement, you will need to get the name of the group which the current user belongs to. Then perform a query in a specific list to get all the items that
    contains the specific value in “Target Audience” field.
    Here is a code snippet about how to set Target Audience for an item, there are code lines about
    how to get the value of a “Target Audience” field:
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/a3ac41d8-42e9-4ec7-999f-036c4b06d3e2/programatically-set-target-audience-in-list-item
    A method about checking whether the current user is a member of the specified group:
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.iscurrentusermemberofgroup.aspx
    Best regards,
    Patrick
    Patrick Liang
    TechNet Community Support

  • How to format a date to display the ISO week number in BI Publisher ?

    Hi there,
    I need to format a date to display the ISO week number in BI Publisher.
    I've tried the following <?format-date:NEED_BY_DATE;'WW'?>, but it returns a week number (1-53) where week 1 starts on the first day of the year and continues to the seventh day of the year, which is not what I want.
    I want the ISO week number (1-52 or 1-53), the one implemented by the 'IW' format mask of the Oracle PL/SQL TO_CHAR() function for example.
    I've tried using 'IW' format mask, but it is not recognised by BI Publisher.
    Also, as I'm working on an RTF template, I've tried 'IW' as MS Word date format, but it is not recognised by MS Word :-((
    Any help would be much appreciated,
    Regards - Hugues

    Hi,
    Thank you for the post.
    The thing is I don't have access to the query, unless I modify a standard E-Businees Suite view (one of those used to generate the PO document in Purchasing).
    Regards - Hugues

  • Report based on the user profile

    Hi,
    i'm trying to create a report with Oracle Report6i based on the user profile.
    I created a form with many Lovs, so that i can choose the parameter to send to the report (using a java script).
    I also would like to send the user that's currently logged in, just in order to filter the output.
    How can i use the api wwctx_api.get_user in the java script ?
    Thanks.

    Hi,
    It is not possible to use the api directly in javascript. Maybe you pass it as a parameter to a javascript function.
    Thanks,
    Sharmila

  • How can I force Time Machine to make a complete backup of my Hard Drive.  I just installed a new external drive for Backup since my previous one failed.  Now when I back up, Time Machine only backs up my data folder and the Users folder.

    How can I force Time Machine to make a complete backup of my Hard Drive.  I just installed a new external drive for Backup since my previous one failed.  Now when I back up, Time Machine only backs up my data folder and the Users folder.
    When I start a backup. Time Machine says "Oldest Backup: None; Latest Backup: None", so it seems like it should do a complete backup, but it only does a partial. 

    Hi I'd like to jump in here. Your app showed me this:
    Time Machine:
              Skip System Files: NO
              Mobile backups: OFF
              Auto backup: YES
              Volumes being backed up:
                        Macintosh HD: Disk size: 749.3 GB Disk used: 453.81 GB
              Destinations:
                        Plastic Wrapper [Local] (Last used)
                        Total size: 999.86 GB
                        Total number of backups: 64
                        Oldest backup: 2013-07-24 23:25:11 +0000
                        Last backup: 2013-11-17 01:40:47 +0000
                        Size of backup disk: Too small
                                  Backup size 999.86 GB < (Disk used 453.81 GB X 3)
              Time Machine details may not be accurate.
              All volumes being backed up may not be listed.
              /sbin excluded from backup!
              /usr excluded from backup!
              /System excluded from backup!
              /bin excluded from backup!
              /private excluded from backup!
              /Library excluded from backup!
              /Applications excluded from backup!
    Aside from the size of my backup drive, which I will increase at some point, I'd really like to have time machine backing up all system folders, especially Applications. How to I reset this hidden exclusions?
    Thanks,
    Darcy

  • I've to extract the data based on the sysdate...like today dd is 11,

    BM_PERF is the table name and
    BM_PERF_YR,BM_PERF_MONTH,BM_NOP_CT_1........BM_NOP_CT_31 are the column names.
    I've to extract the data based on the sysdate...like today dd is 11
    so i've to get data from BM_NOP_CT_11 and the column names changes dynamically based on the sysdate. don't use any procedures and functions.

    You could always pivot it into a more convenient form for querying:
    WITH t1 AS
         ( SELECT 2008 AS yr, 4 AS mnth
                , 20 AS dy1
                , 10 AS dy2
                , 15 AS dy3
                , 1  AS dy4
                , 17 AS dy5
                , 99 AS dy6
                , 55 AS dy7
                , 45 AS dy8
                , 33 AS dy9
                , 22 AS dy10
                , 74 AS dy11
                , 35 AS dy12
                , 62 AS dy13
                , 24 AS dy14
                , 85 AS dy15
           FROM dual )
       , t2 AS
         ( SELECT yr
                , mnth
                , sys.DBMS_DEBUG_VC2COLL
                  (dy1,dy2,dy3,dy4,dy5,dy6,dy7,dy8,dy9,dy10,dy11,dy12,dy13,dy14,dy15)
                  AS day_data
           FROM   t1 )
    SELECT t2.yr, t2.mnth, sys_op_ceg(t2.day_data,5) day_value
    FROM   t2;
            YR       MNTH DAY_VALUE
          2008          4 17
    1 row selected.Note that SYS_OP_CEG (first discovered by Padders) is undocumented and unsupported - for production code you'd need to pick the collection row using a WHERE clause, and for that you'd need a custom object and collection type with an attribute to hold the day number.
    Message was edited by:
    William Robertson
    ...like this:
    CREATE TYPE id_value_ot AS OBJECT
    ( id INTEGER, val NUMBER );
    CREATE TYPE id_value_tt AS TABLE OF id_value_ot ;
    WITH t1 AS
         ( SELECT 2008 AS yr, 4 AS mnth
                , 20 AS dy1
                , 10 AS dy2
                , 15 AS dy3
                , 1  AS dy4
                , 17 AS dy5
                , 99 AS dy6
                , 55 AS dy7
                , 45 AS dy8
                , 33 AS dy9
                , 22 AS dy10
                , 74 AS dy11
                , 35 AS dy12
                , 62 AS dy13
                , 24 AS dy14
                , 85 AS dy15
           FROM dual )
       , t2 AS
         ( SELECT yr
                , mnth
                , id_value_tt
                  ( id_value_ot(1,dy1)
                  , id_value_ot(2,dy2)
                  , id_value_ot(3,dy3)
                  , id_value_ot(4,dy4)
                  , id_value_ot(5,dy5)
                  , id_value_ot(6,dy6)
                  , id_value_ot(7,dy7)
                  , id_value_ot(8,dy8)
                  , id_value_ot(9,dy9)
                  , id_value_ot(10,dy10)
                  , id_value_ot(11,dy11)
                  , id_value_ot(12,dy12)
                  , id_value_ot(13,dy13)
                  , id_value_ot(14,dy14)
                  , id_value_ot(15,dy15) )
                  AS day_data
           FROM   t1 )
    SELECT yr, mnth, dd.val
    FROM   t2, TABLE(t2.day_data) dd
    WHERE  dd.id = 5;
            YR       MNTH        VAL
          2008          4         17
    1 row selected.

  • Purchasing Group authorization based on the user

    Hi All,
    Can anyone suggest me ideas on how to restrict in accessing details of a PO for a  purchasing group based on the user who tries to access it .
    the object is M-BEST_EKG.
    need guidance in using AUTHORITY_CHECK in restriciting PO group based on the userid.
    Thanks in advance.
    Regards,
    Ry

    Hi,
    ACTIVITY controls what user can do to the PO.
    01-Create
    02-Change
    03-Display
    EKGRP controls the purchasing group
    To restrict to a specific purchasing group, modify the authorization object in the role which user has to allow the specfic P.Grp. only
    Cheers !

  • Determine Business partner number based on the user id

    Hi all,
    Is there a way to determine the BP number of an employee based on the user id. The employee is created as a BP with role Employee in the system.
    I'm checking USR02 and BUT000.. But i find no link between them.
    Thank you,
    Preethi

    Hi Preethi
    Try this
    *Get the BP Guid by passign the user name here
      CALL FUNCTION 'BP_CENTRALPERSON_GET'
        EXPORTING
          IV_USERNAME         = lv_username
        IMPORTING
          EV_BU_PARTNER_GUID  = lv_bp_guid
        EXCEPTIONS
          NO_CENTRAL_PERSON   = 1
          NO_BUSINESS_PARTNER = 2
          NO_ID               = 3
          OTHERS              = 4.
    *Get the BP Numbere here
      CALL FUNCTION 'CMS_BUPA_NUMBERS_READ_BL'
        EXPORTING
          IV_PARTNER_GUID         = lv_bp_guid
        IMPORTING
          EV_PARTNER_ID           = lv_bpnumber
        EXCEPTIONS
          NO_PARTNER_SPECIFIED    = 1
          NO_VALID_RECORD_FOUND   = 2
          INCONSISTENT_PARAMETERS = 3
          NO_ADDRESS_FOUND        = 4
          OTHERS                  = 5.
    Reward if this helps.
    Thanks

  • Different masterhead image based on the user logged in portal

    HI,
    Presently we are using standard portal theme.How can I change the image in the masterhead based on the user logged in.How can i change that and i want to assign that masteredhead to users.
    Can anybody give me suggesion about this.
    Thanks,
    Regards,
    Srinivas

    Dear Srinivas,
    Simple of achiving this kind of scnario is create separate themes for different users and assign the themes to the users in master rule collection through Desktop Page.Here in this case you will be creating one framework page and multiple Desktops and themes.All the desktops will be having the same framework page and different themes based on the user type or group type.
    Otherway of achiving this is create an pdk application where it will have multiple jsp components in it and based on the each component create one PAR iview.Let us take if four groups of users then you will be creating four different jsps in pdk application which will inturn contains different masterhead images and related logos.After creating the iview place the iview in the correcsponding framework page below the masterhead iview.Here multiple framework pages and Desktops and you can go with single theme.
    In the first scenario the masteread , we are managing through the theme and in second the masterhead we are managing throgh application.
    Either of the scenarios can be used to create differet masterheads for different users.
    Hope the answer helps you....
    Reward the points if it is helpful.
    Thanks,
    Rudradev Devulapalli

Maybe you are looking for